home *** CD-ROM | disk | FTP | other *** search
/ ftp.alaska-software.com / 2014.06.ftp.alaska-software.com.tar / ftp.alaska-software.com / acsn / History / BDVIDEO / BDVIDEO.ZIP / BDVIDEO.PRG next >
Text File  |  2002-08-14  |  14KB  |  383 lines

  1. //////////////////////////////////////////////////////////////////////////////
  2. //
  3. //      BDVideo Class - BDTools Library
  4. //              2001 - Brent Dubs ( bdubs@vanityshops.com )
  5. //
  6. //      Uses the XPPMM.PRG from Gernot Trautmann availible in
  7. //        the ASCN section of Alaska Software's website
  8. //        www.alaska-software.com
  9. //
  10. //      Version level
  11. //              1.2 - Added methods: SetPos, SetSize, SetPosAndSize,
  12. //                                   and Ready
  13. //
  14. //              1.1 - Added methods: SetVolume, Mute, SetSpeed, Rewind,
  15. //                                   FreezeRect, SaveFrame, Quality,
  16. //                                   Seek, GetPosition, and FrameStep
  17. //                    Added ivars: length, frames, volume, muted
  18. //
  19. //              1.0 - Original version
  20. //
  21. //////////////////////////////////////////////////////////////////////////////
  22.  
  23. #include "Common.ch"
  24. #include "Xbp.ch"
  25. #include "Xppmm.ch"
  26.  
  27. CLASS BDVideo FROM XbpStatic
  28.         EXPORTED
  29.         VAR     Ret
  30.         VAR     handle
  31.         VAR     error           // Error value of last command
  32.         VAR     errorString     // Text description of error
  33.         VAR     filename        // File loaded
  34.         VAR     opened          // Is file opened
  35.         VAR     paused          // Is video paused
  36.         VAR     volume          // Volume level (0-1000)
  37.         VAR     length          // Length of video in seconds
  38.         VAR     frames          // Number of frames in the video
  39.         VAR     muted           // Is audio muted
  40.  
  41.         METHOD  Init
  42.         METHOD  Create
  43.         METHOD  Destroy
  44.         METHOD  LoadFile        // Load the file
  45.         METHOD  Play            // Play the video
  46.         METHOD  Pause           // Pause the video
  47.         METHOD  Stop            // Stop the video
  48.         METHOD  GetErrorString  // Retreive the descripion of the error
  49.         METHOD  Status          // Retreive the playing status of the video
  50.         METHOD  Ready           // Retreive the ready status of the MCI device
  51.         METHOD  SetPos          // Set the display position of the video
  52.         METHOD  SetSize         // Set the display size of the video
  53.         METHOD  SetPosAndSize   // Set the display position and size of the video
  54.         METHOD  SetVolume       // Set the volume level in percentage (0-100%)
  55.         METHOD  Mute            // Set the audio off/on
  56.         METHOD  SetSpeed        // Increase/decrease the playing speed
  57.         METHOD  Seek            // Seek to a spot in the video in seconds
  58.         METHOD  FrameStep       // Seek ahead or back in Frames (+ or -)
  59.         METHOD  GetPosition     // Return the number of seconds into the video
  60.         METHOD  Rewind          // Play video in reverse (not always supported)
  61.         METHOD  FreezeRect      // Freeze a frame rect (not always supported)
  62.         METHOD  SaveFrame       // Save a frame to a JPEG file (not always supported)
  63.         METHOD  Quality         // Return the quality of video (not always supported)
  64. ENDCLASS
  65.  
  66. //-----------------------------------------------------------------------------
  67.  
  68. METHOD BDVideo:Init( oParent, oOwner, aPos, aSize, aPP, lVisible )
  69.    DEFAULT aPP TO {}
  70.    ::XbpStatic:init( oParent, oOwner, aPos, aSize, aPP, lVisible )
  71.    ::XbpStatic:type := XBPSTATIC_TYPE_TEXT
  72.    ::error := 0
  73.    ::errorString := ""
  74.    ::Ret := SPACE(50)
  75.    ::filename := ""
  76.    ::opened := .F.
  77.    ::handle := ""
  78.    ::paused := .F.
  79.    ::volume := 1000
  80.    ::Length := 0
  81.    ::frames := 0
  82.    ::muted := .F.
  83.    ::volume := 100
  84. RETURN self
  85.  
  86. //-----------------------------------------------------------------------------
  87.  
  88. METHOD BDVideo:Create( oParent, oOwner, aPos, aSize, aPP, lVisible )
  89.   ::XbpStatic:Create( oParent, oOwner, aPos, aSize, aPP, lVisible )
  90. RETURN self
  91.  
  92. //-----------------------------------------------------------------------------
  93.  
  94. METHOD BDVideo:Destroy()
  95.   IF ::opened
  96.     ::error := mmSendString( "close movie", @::Ret )
  97.     ::getErrorString()
  98.   ENDIF
  99.   ::XbpStatic:destroy()
  100. RETURN
  101.  
  102. //-----------------------------------------------------------------------------
  103. // Open the specified file and prepare it for playing.
  104.  
  105. METHOD BDVideo:loadFile(cFileName)
  106.   ::filename := cFileName
  107.   ::handle := Transform(::XbpStatic:getHwnd(),"9999999999")
  108.   IF ::opened  // A file is already loaded...close it.
  109.     ::error := mmSendString( "close movie", @::Ret )
  110.     ::getErrorString()
  111.   ENDIF
  112.   ::Ret := SPACE(50)
  113.  
  114.   // Open the file
  115.   ::error := mmSendString( "open "+ '"' + cFileName + '"' + " parent "+ ;
  116.                          ::handle +" style child alias movie" , @::Ret)
  117.   ::getErrorString()
  118.  
  119.   // Detect the length in frames
  120.   mmSendString( "set movie time format frames", @::Ret )
  121.   mmSendString( "status movie length", @::Ret )
  122.   ::frames := IF(ValType(::Ret)=="C",VAL(::Ret),0)
  123.  
  124.   // Detect the length in seconds
  125.   mmSendString( "set movie time format milliseconds", @::Ret )
  126.   mmSendString( "status movie length", @::Ret )
  127.   ::length := IF(ValType(::Ret)=="C",VAL(::Ret),0)
  128.  
  129.   // Detect the volumn level
  130.   mmSendString( "status movie volume", @::Ret )
  131.   ::volume := INT(VAL(::Ret)/10)
  132.  
  133.   // Create the display window
  134.   IF ::error == 0
  135.     ::error := mmSendString( "put movie window at 0 0 " +;
  136.                              AllTrim(STR(::XbpStatic:currentSize()[1])) + " " +;
  137.                              AllTrim(STR(::XbpStatic:currentSize()[2])) +;
  138.                              " wait ", @::Ret )
  139.     ::getErrorString()
  140.     ::opened := .T.
  141.   ENDIF
  142. RETURN ::error
  143.  
  144. //-----------------------------------------------------------------------------
  145. // Set the position and size of the video display
  146.  
  147. METHOD BDVideo:setPosAndSize(aPos,aSize,lPaint)
  148.   LOCAL lSuccess := .T.
  149.   DEFAULT lPaint TO .T.
  150.   lSuccess := ::XbpStatic:setPosandSize(aPos,aSize,lPaint)
  151.   ::error := mmSendString( "put movie window at 0 0 " +;
  152.                            AllTrim(STR(aSize[1])) + " " +;
  153.                            AllTrim(STR(aSize[2])) +;
  154.                            " wait ", @::Ret )
  155.   ::getErrorString()
  156. RETURN lSuccess
  157.  
  158. //-----------------------------------------------------------------------------
  159. // Set the position of the video display
  160.  
  161. METHOD BDVideo:setPos(aPos,lPaint)
  162.   LOCAL lSuccess := .T.
  163.   DEFAULT lPaint TO .T.
  164.   lSuccess := ::XbpStatic:setPos(aPos,lPaint)
  165. RETURN lSuccess
  166.  
  167. //-----------------------------------------------------------------------------
  168. // Set the size of the video display
  169.  
  170. METHOD BDVideo:setSize(aSize,lPaint)
  171.   LOCAL lSuccess := .T.
  172.   DEFAULT lPaint TO .T.
  173.   lSuccess := ::XbpStatic:setSize(aSize,lPaint)
  174.   ::error := mmSendString( "put movie window at 0 0 " +;
  175.                            AllTrim(STR(aSize[1])) + " " +;
  176.                            AllTrim(STR(aSize[2])) +;
  177.                            " wait ", @::Ret )
  178.   ::getErrorString()
  179. RETURN lSuccess
  180.  
  181. //-----------------------------------------------------------------------------
  182. // Make the error string availible.
  183.  
  184. METHOD BDVideo:getErrorString()
  185.   IF ::error != 0
  186.     ::errorString := mmGetErrString(::error)
  187.   ELSE
  188.     ::errorString := ""
  189.   ENDIF
  190. RETURN ::errorString
  191.  
  192. //-----------------------------------------------------------------------------
  193. // Check the status of the video clip.
  194. //   Returns "playing", "paused", "stopped", etc.
  195.  
  196. METHOD BDVideo:status()
  197.   ::error := mmSendString( "status movie mode", @::Ret )
  198. RETURN ALLTRIM(::Ret)
  199.  
  200. //-----------------------------------------------------------------------------
  201. // Check the ready status of the video clip.
  202. //   Returns .T. if MCI device is ready for another command
  203.  
  204. METHOD BDVideo:ready()
  205.   ::error := mmSendString( "status movie ready", @::Ret )
  206.   ::getErrorString()
  207.   ::Ret := STRTRAN(::Ret,CHR(0))
  208. RETURN (UPPER(AllTrim(::Ret)) == "TRUE") .OR. EMPTY(::Ret)
  209.  
  210. //-----------------------------------------------------------------------------
  211. // Play the video clip
  212.  
  213. METHOD BDVideo:Play(lFromStart,lWait,lRepeat)
  214.   DEFAULT lFromStart TO .F.
  215.   DEFAULT lWait TO .F.
  216.   DEFAULT lRepeat TO .F.
  217.   IF lFromStart  // Play from the beginning of the clip.
  218.     IF ::opened  // If another clip is loaded...close it,
  219.       ::error := mmSendString( "close movie", @::Ret )
  220.     ENDIF
  221.     ::loadfile(::filename)
  222.   ENDIF
  223.   ::paused := .F.  // If paused, it no longer is.
  224.   IF lWait  // Freeze execution until the clip is finished.
  225.     ::error := mmSendString( "play movie wait", @::Ret )
  226.     ::stop()
  227.   ELSE
  228.     IF lRepeat  // Repeat the clip in loops.
  229.       ::error := mmSendString( "play movie repeat", @::Ret )
  230.     ELSE
  231.       ::error := mmSendString( "play movie", @::Ret )
  232.     ENDIF
  233.   ENDIF
  234.   ::getErrorString()
  235. RETURN ::error
  236.  
  237. //-----------------------------------------------------------------------------
  238. // Pause the video clip
  239.  
  240. METHOD BDVideo:Pause(lPlayIfPaused)
  241.   DEFAULT lPlayIfPaused TO .F.
  242.   IF ::paused
  243.     IF lPlayIfPaused  // If it was previously paused then un-pause it.
  244.       ::paused := .F.
  245.       ::error := mmSendString( "play movie", @::Ret )
  246.     ENDIF
  247.   ELSE
  248.     ::error := mmSendString( "pause movie", @::Ret )
  249.     ::paused := .T.
  250.   ENDIF
  251.   ::getErrorString()
  252. RETURN ::error
  253.  
  254. //-----------------------------------------------------------------------------
  255. // Stop the video clip from playing
  256.  
  257. METHOD BDVideo:Stop()
  258.   IF ::opened
  259.     ::error := mmSendString( "stop movie", @::Ret )
  260.   ENDIF
  261.   ::getErrorString()
  262. RETURN ::error
  263.  
  264. //-----------------------------------------------------------------------------
  265. // Jump to position in video clip in seconds
  266.  
  267. METHOD BDVideo:Seek(nSeconds)
  268.   LOCAL lPlaying := ::status() == "playing"
  269.   LOCAL nOldPosition := ::GetPosition()
  270.   nSeconds := ROUND(nSeconds,0) * 1000
  271.   ::error := mmSendString( "seek movie to " + ALLTRIM(STR(nSeconds)), @::Ret )
  272.   ::getErrorString()
  273.   IF lPlaying
  274.     mmSendString( "play movie", @::Ret )
  275.   ENDIF
  276. RETURN nOldPosition
  277.  
  278. //-----------------------------------------------------------------------------
  279. // Jump to position in video clip in frames
  280.  
  281. METHOD BDVideo:FrameStep(nFrames)
  282.   LOCAL lPlaying := ::status() == "playing"
  283.   ::error := mmSendString( "step movie by " + ALLTRIM(STR(nFrames)), @::Ret )
  284.   ::getErrorString()
  285.   IF lPlaying
  286.     mmSendString( "play movie", @::Ret )
  287.   ENDIF
  288. RETURN
  289.  
  290. //-----------------------------------------------------------------------------
  291. // Set the speed of the video clip in percentages
  292. //      50 = 50% speed (0.5x), 100 = 100% (normal), 200 = 200% speed (2x)
  293.  
  294. METHOD BDVideo:SetSpeed(nSpeed)
  295.   DEFAULT nSpeed TO 100  // set to the regular speed
  296.   nSpeed := nSpeed * 10
  297.   ::error := mmSendString( "set movie speed " + ALLTRIM(STR(INT(nSpeed))), @::Ret )
  298.   ::getErrorString()
  299. RETURN
  300.  
  301. //-----------------------------------------------------------------------------
  302. // Get the current positon in seconds
  303.  
  304. METHOD BDVideo:GetPosition()
  305.   ::error := mmSendString( "status movie position", @::Ret )
  306.   ::getErrorString()
  307. RETURN (VAL(::Ret)/1000)
  308.  
  309. //-----------------------------------------------------------------------------
  310. // Turn the audio off/on
  311.  
  312. METHOD BDVideo:Mute(lOn)
  313.   DEFAULT lOn TO .T.
  314.   IF lOn  // Turn sound off
  315.     ::error := mmSendString( "set movie audio all off", @::Ret )
  316.     ::muted := .T.
  317.   ELSE  // Turn sound on
  318.     ::error := mmSendString( "set movie audio all on", @::Ret )
  319.     ::muted := .F.
  320.   ENDIF
  321.   ::getErrorString()
  322. RETURN
  323.  
  324. //-----------------------------------------------------------------------------
  325. // Set the audio volume level to percentage
  326. //      0 = 0% (No sound), 50 = 50% (half-volume), 100 = 100% (full volume)
  327.  
  328. METHOD BDVideo:SetVolume(nLevel)
  329.   DEFAULT nLevel TO 100
  330.   IF nLevel < 0
  331.     nLevel := 0
  332.   ENDIF
  333.   IF nLevel > 100
  334.     nLevel := 100
  335.   ENDIF
  336.   ::volume := nLevel
  337.   ::error := mmSendString( "setaudio movie volume to "+ALLTRIM(STR(INT(nLevel*10))), @::Ret )
  338.   ::getErrorString()
  339. RETURN
  340.  
  341. //-----------------------------------------------------------------------------
  342. // Returns the quality of the video
  343. //    This is not supported by all MCI devices (check :errorstatus)
  344.  
  345. METHOD BDVideo:quality()
  346.   ::error := mmSendString( "info movie video quality", @::Ret )
  347.   ::getErrorString()
  348. RETURN ::Ret
  349.  
  350. //-----------------------------------------------------------------------------
  351. // Saves current frame to a JPEG file
  352. //    This is not supported by all MCI devices (check :errorstatus)
  353.  
  354. METHOD BDVideo:SaveFrame(cFileName)
  355.   mmSendString( "set movie file format jpeg", @::Ret )
  356.   ::error := mmSendString( "capture movie as " + cFileName, @::Ret )
  357.   ::getErrorString()
  358. RETURN
  359.  
  360. //-----------------------------------------------------------------------------
  361. // Freeze a rectagle area of the video
  362. //    This is not supported by all MCI devices (check :errorstatus)
  363.  
  364. METHOD BDVideo:freezeRect(aPos,aSize)
  365.   ::error := mmSendString( "freeze movie at " +;
  366.                             ALLTRIM(STR(aPos[1])) + " " +;
  367.                             ALLTRIM(STR(aPos[2])) + " " +;
  368.                             ALLTRIM(STR(aSize[1])) + " " +;
  369.                             ALLTRIM(STR(aSize[2])), @::Ret )
  370.    ::getErrorString()
  371. RETURN
  372.  
  373. //-----------------------------------------------------------------------------
  374. // Play the video in reverse
  375. //    This is not supported by all MCI devices (check :errorstatus)
  376.  
  377. METHOD BDVideo:rewind()
  378.   ::error := mmSendString( "play movie reverse", @::Ret )
  379.   ::getErrorString()
  380. RETURN
  381.  
  382. //-----------------------------------------------------------------------------
  383.