1. --!movie
  2. --!encoding=utf-8
  3.  
  4. global $
  5.  
  6. global gWindowID
  7.  
  8. ----------------------------------------
  9. --
  10. ----------------------------------------
  11. on startMovie
  12.  
  13.   -- libs
  14.   $.import("console").show()
  15.   $.import("avmedia")
  16.     $.import("shell")
  17.    
  18.   -- specify path to video file (as HFS path)
  19.   fn = $.PATH & "big_buck_bunny.mp4"
  20.  
  21.   -- set callback that is triggered when video is ready to play
  22.   $.avmedia.setReadyStatusChangeCallback(#videoReadyForDisplay)
  23.  
  24.   -- set callback that is triggered when video window was closed
  25.   $.avmedia.setWindowClosedCallback(#halt, _movie)
  26.  
  27.   -- open the video window (hidden)
  28.   -- videoOpen object me, string pathOrURL, object rect, *stayOnTop, windowMask, overlayFlag, windowTitle
  29.     gWindowID = $.avmedia.videoOpen(fn, rect(0,0,0,0), FALSE, $.avmedia.MASK.StandardWin)
  30.  
  31. end
  32.  
  33. ----------------------------------------
  34. -- @callback
  35. ----------------------------------------
  36. on videoReadyForDisplay (status)
  37.  
  38.   monitorRect = _system.desktopRectList[1]
  39.  
  40.   -- test: play with 640*360 at screen center
  41.   w = 640
  42.   h = 360
  43.   x = (monitorRect.width - w)/2
  44.   y = (monitorRect.height - h)/2
  45.   playRect = rect(x, y, x+w, y+h)
  46.  
  47.     -- show video window
  48.     $.avmedia.videoSetRect(playRect)
  49.      
  50.   -- start playing (at default speed)
  51.   $.avmedia.videoSetRate(1.0)
  52.  
  53.   -- grab first frame as image
  54.   m = new(#bitmap)
  55.   captureCurrentVideoFrame (m)
  56.  
  57. end
  58.  
  59. ----------------------------------------
  60. -- Grabs image of current video frame
  61. -- Usage:
  62. -- m = new(#bitmap)
  63. -- captureCurrentVideoFrame(m)
  64. -- --> member m now contains a bitmap of the curent video frame
  65. ----------------------------------------
  66. --on captureCurrentVideoFrame (memRef)
  67. --  r = $.avmedia.videoGetRect()
  68. --  cmd = "/usr/sbin/screencapture -c -R"&r.left&","&r.top&","&r.width&","&r.height
  69. --  $.shell.shell_cmd(cmd)
  70. --  memRef.pasteClipBoardInto()
  71. --end
  72.  
  73. ----------------------------------------
  74. -- Grabs image of current video frame
  75. -- Usage:
  76. -- m = new(#bitmap)
  77. -- captureCurrentVideoFrame(gWindowID, m)
  78. -- --> member m now contains a bitmap of the curent video frame
  79. ----------------------------------------
  80. on captureCurrentVideoFrame (memRef)
  81.   cmd = "/usr/sbin/screencapture -c -o -l"&gWindowID
  82.   $.shell.shell_cmd(cmd)
  83.   memRef.pasteClipBoardInto()
  84. end
  85.  
[raw code]