home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 14 / 14.iso / s / s005 / 25.ddi / PACK0.PK1 / PLAY.CMD < prev    next >
Encoding:
Text File  |  1993-03-19  |  6.5 KB  |  254 lines

  1. /*-----------------------------------------------------------------------------
  2.  
  3.   Name:                   play.cmd
  4.   Date Created:    12/27/92
  5.                 Copyright (c) IBM Corporation  1992, 1993
  6.                           All Rights Reserved
  7.  
  8.  
  9.   OS/2 REXX command file that uses MultiMedia REXX functions
  10.   to play a file.
  11.  
  12.  -----------------------------------------------------------------------------*/
  13.  
  14. address cmd      /* Send commands to OS/2 command processor.  */
  15. signal on error   /* When commands fail, call "error" routine. */
  16.  
  17. trace off
  18. /*trace ?r*/
  19.  
  20. arg arg1 arg2 arg3 arg4 arg5         /* Fetch command line parms */
  21.  
  22. if (arg1='' | arg1='?') then
  23.    do
  24.      call Help
  25.      exit 0
  26.    end
  27.  
  28. parse var arg1 arg1a'='arg1b
  29. parse var arg2 arg2a'='arg2b
  30. parse var arg3 arg3a'='arg3b
  31. parse var arg4 arg4a'='arg4b
  32. parse var arg5 arg5a'='arg5b
  33.  
  34. /* initialize variables */
  35. FILE=''
  36. FROM=''
  37. TO=''
  38. DEV=''
  39. TIMEFMT=''
  40.  
  41. /* Set the variables. */
  42. call keyword arg1a, arg1b
  43. call keyword arg2a, arg2b
  44. call keyword arg3a, arg3b
  45. call keyword arg4a, arg4b
  46. call keyword arg5a, arg5b
  47.  
  48. /* Load the DLL, initialize MCI REXX support */
  49. rc = RXFUNCADD('mciRxInit','MCIAPI','mciRxInit')
  50. InitRC = mciRxInit()
  51. MciCmd = 'open'
  52.  
  53. /*
  54. ** Check to see if the FILE && DEV variables are valid.
  55. */
  56.      if FILE<>'' then
  57.         do
  58.           if DEV<>'' then
  59.              MciCmd = MciCmd FILE 'type' DEV
  60.           else
  61.              MciCmd = MciCmd FILE
  62.         end
  63.      else if DEV<>'' then
  64.         MciCmd = MciCmd DEV
  65.      else
  66.            do
  67.              call Help
  68.              exit 0
  69.            end
  70.  
  71. /*
  72. ** Append the rest of the command line.
  73. */
  74.     MciCmd = MciCmd 'alias rexxalias wait'
  75.  
  76. /*
  77. ** Issue the open command.
  78. */
  79.     MacRC = SendString(MciCmd)
  80.      if MacRC <> 0 then signal ErrExit
  81.      else
  82.      do
  83.        if DEV='' then    /* device not specified */
  84.          do     /* determine the device type */
  85.           MacRC = SendString("capability rexxalias device type wait")
  86.           if MacRC <> 0 then
  87.               do
  88.                  junk = SendString("close rexxalias wait")
  89.                  signal ErrExit
  90.               end
  91.          end
  92.        else   /* set the device specified as the device type */
  93.          RetSt = DEV
  94.  
  95.        /* If a wave file is to be played then do a status length */
  96.        /* to determine if the wave file exists.  A wave file is  */
  97.        /* the only type of device that if it doesn't exist and   */
  98.        /* you play it, it won't come back as file not found      */
  99.        if TRANSLATE(RetSt) = 'WAVEAUDIO' then
  100.          do
  101.             MacRC = SendString("status rexxalias length wait")      /* If length is 0 no file exists */
  102.              if MacRC <> 0 then
  103.               do
  104.                  junk = SendString("close rexxalias wait")
  105.                  signal ErrExit
  106.               end
  107.              if RetSt = 0 then
  108.               do
  109.                  junk = SendString("close rexxalias wait")
  110.                  ErrRC = 70555
  111.                  MacRC = mciRxGetErrorString(ErrRC, 'ErrStVar')
  112.                  say 'mciRxGetErrorString('ErrRC') =' ErrStVar
  113.                  signal ErrExit
  114.               end
  115.          end
  116.      end
  117.  
  118. /*
  119. ** Exercise mciRxGetDeviceID function
  120. */
  121. DeviceID = mciRxGetDeviceID(""rexxalias"")
  122.  
  123. /*
  124. **  Check to see if a time format was given.
  125. */
  126. if TIMEFMT <> '' then
  127. do
  128.     MciCmd = 'set rexxalias time format' TIMEFMT 'wait'
  129.     MacRC = SendString(MciCmd)
  130.      if MacRC <> 0 then
  131.         do
  132.          junk = SendString("close rexxalias wait")
  133.          signal ErrExit
  134.         end
  135. end
  136.  
  137. /*
  138. ** Formulate the play command.
  139. */
  140. MciCmd = 'play rexxalias'
  141.  
  142. /*
  143. ** check to see if an origin was set.
  144. */
  145.  if FROM<>'' then
  146.         MciCmd = MciCmd 'from' FROM
  147.  
  148. /*
  149. ** check to see if a terminating point was given.
  150. */
  151.  if TO<>'' then
  152.         MciCmd = MciCmd 'to' TO
  153.  
  154. /*
  155. ** append a wait onto the end of the play string.
  156. */
  157. MciCmd = MciCmd 'wait'
  158.  
  159. /*
  160. ** actually send the play string.
  161. */
  162. MacRC = SendString(MciCmd)
  163.      if MacRC <> 0 then
  164.         do
  165.          junk = SendString("close rexxalias wait")
  166.          signal ErrExit
  167.         end
  168.  
  169. /*
  170. ** close the instance.
  171. */
  172. MacRC = SendString("close rexxalias wait")
  173. if MacRC <> 0 then signal ErrExit
  174.  
  175. /*
  176. ** Exit, return code = 0.
  177. */
  178. exit 0
  179.  
  180. /*   --- SendString --
  181. ** Call DLL function.  Pass the command to process and the
  182. ** name of a REXX variable that will receive textual return
  183. ** information.
  184. */
  185. SendString:
  186.    arg CmndTxt
  187.    /* Last two parameters are reserved, must be set to 0           */
  188.    /* Future use of last two parms are for notify window handle    */
  189.    /* and userparm.                                                 */
  190.    MacRC = mciRxSendString(CmndTxt, 'RetSt', '0', '0')
  191.    if MacRC<>0 then
  192.       do
  193.       ErrRC = MacRC
  194.       say 'MciCmd=' CmndTxt
  195.       say 'Err:mciRxSendString RC=' ErrRC RetSt
  196.       MacRC = mciRxGetErrorString(ErrRC, 'ErrStVar')
  197.       say 'mciRxGetErrorString('ErrRC') =' ErrStVar
  198.       MacRC = ErrRC /* return the error rc */
  199.       end
  200.    return MacRC
  201.  
  202. /* -- keywords --
  203. **
  204. ** Parse the arguments according to the keywords.
  205. */
  206. keyword:
  207.         arg key, value
  208.         if key='FILE' then
  209.             FILE=value
  210.         else if key='DEV' then
  211.             DEV=value
  212.         else if key='FROM' then
  213.              FROM=value
  214.         else if key='TO' then
  215.               TO=value
  216.         else if key='TIMEFMT' then
  217.                 TIMEFMT=value
  218.  
  219. return
  220.  
  221. /*  -- help --
  222. ** Display help text
  223. */
  224. Help:
  225.    say
  226.    say 'This command file plays a file or device using the MultiMedia'
  227.    say 'REXX string interface.'
  228.    say
  229.    say 'play [FILE=filename] [DEV=device] [TIMEFMT=timefmt]'
  230.    say '         [FROM=from_position] [TO=to_position]'
  231. return
  232.  
  233. /*  --- ErrExit --
  234. ** Common routine for error clean up/program exit.
  235. ** Gets called when commands to DLL fail.
  236. */
  237. ErrExit:
  238.    MacRC = mciRxExit()   /* Tell the DLL we're going away        */
  239.    exit 1;               /* exit, tell caller things went poorly */
  240.  
  241.  
  242. /*   ---- error --
  243. ** Routine gets control when any command to the external
  244. ** environment (usually OS/2) returns a non-zero RC.
  245. ** This routine does not get called when the macapi.dll
  246. ** returns non-zero as it is a function provider rather
  247. ** than a command environment.
  248. */
  249. error:
  250.    ErrRC = rc
  251.    say 'Error' ErrRC 'at line' sigl ', sourceline:' sourceline(sigl)
  252.    MacRC = mciRxExit()       /* Tell the DLL we're going away */
  253.    exit ErrRC                /* exit, tell caller things went poorly */
  254.