home *** CD-ROM | disk | FTP | other *** search
/ Magazyn Exec 5 / CD_Magazyn_EXEC_nr_5.iso / Recent / mus / play / mp3Play.lha / mp3play / mp3Play < prev    next >
Text File  |  2001-06-03  |  2KB  |  125 lines

  1. /*
  2.   mp3Play.rx © 2001 Carl Svensson
  3. */
  4.  
  5. if ~show("L","rexxreqtools.library") then
  6.   call addlib("rexxreqtools.library",5,-30)
  7. if ~show("L","rexxsupport.library") then
  8.   call addlib("rexxsupport.library",0,-30,0)
  9.  
  10. /* set up vars */
  11. wtitle="mp3Play"
  12. btext="© 2001 Carl Svensson"
  13. gdata="_Play|_Stop|_Quit"
  14.  
  15. cfg.prog="" /* path to mpega */
  16. cfg.opts="" /* mpega options */
  17. cfg.mp3d="" /* mp3 directory */
  18. call readconfig()
  19.  
  20. tlist="rt_reqpos=reqpos_topleftscr rt_leftoffset=453 rt_topoffset=34"
  21.  
  22. choice=0
  23.  
  24. mp3file=""
  25.  
  26. playing=0
  27.  
  28. response.play=1
  29. response.stop=2
  30. response.quit=3
  31.  
  32. call gui()
  33.  
  34. exit;
  35.  
  36. /* ------ subs ------ */
  37.  
  38. gui: expose response.
  39.   choice=rtezrequest(btext,gdata,wtitle,tlist)
  40.   mp3file=""
  41.   select
  42.     when choice=response.play then
  43.       call play()
  44.     when choice=response.stop then
  45.       call stop(1)
  46.     otherwise
  47.       call quit()
  48.   end
  49. return
  50.  
  51. quit:
  52.   if playing=1 then
  53.     call stop(0)
  54.   exit;
  55. return
  56.  
  57. play: expose cfg.
  58.   if playing=1 then do
  59.     call stop(0)
  60.   end
  61.   if mp3file="" then do
  62.     call load()
  63.   end
  64.   address command "run <>nil: "cfg.prog" "cfg.opts" "mp3file" <>nil:"
  65.   playing=1
  66.   btext=stripfilename(mp3file)
  67.   call gui()
  68. return
  69.  
  70. stop: expose cfg.
  71.   parse arg dogui
  72.   if checkfortask(cfg.prog) then
  73.     address command "break `status com="cfg.prog"`"
  74.   btext="No File"
  75.   playing=0
  76.   if dogui=1 then
  77.     call gui()
  78. return
  79.  
  80. load: expose cfg.
  81.   mp3file=rtfilerequest(cfg.mp3d,"","Pick MP3")
  82.   call play()
  83. return
  84.  
  85. stripfilename: procedure
  86.   parse arg fn
  87.   slash=lastpos("/",fn)
  88.   fname=substr(fn,slash+1)
  89. return fname
  90.  
  91. readconfig: expose cfg.
  92.   if ~exists("s:mp3play.cfg") then do
  93.     say "No CFG file found"
  94.     exit
  95.   end
  96.  
  97.   open(cfile,"s:mp3play.cfg","R")
  98.   cline=readln(cfile)
  99.   
  100.   len=length(cline)
  101.  
  102.   fsplit=pos(";",cline)+1
  103.   lsplit=lastpos(";",cline)+1
  104.  
  105.   cfg.prog=substr(cline,1,fsplit-2)
  106.   cfg.mp3d=substr(cline,fsplit,lsplit-fsplit-1)
  107.   cfg.opts=substr(cline,lsplit)
  108.  
  109.   close(cfile)
  110. return
  111.  
  112. checkfortask: procedure
  113.   parse arg tname
  114.   if exists("env:c4t_out") then
  115.     delete("env:c4t_out")
  116.   address command "status com="tname" > env:c4t_out"
  117.   open(fptr,"env:c4t_out","R")
  118.   fdata=readln(fptr)
  119.   close(fptr)
  120.   if length(fdata)=0 then
  121.     running=0
  122.   else
  123.     running=1
  124. return running
  125.