--!movie
--!encoding=utf-8
global $
global gWindowID
----------------------------------------
--
----------------------------------------
on startMovie
-- libs
$.import("console").show()
$.import("avmedia")
$.import("shell")
-- specify path to video file (as HFS path)
fn = $.PATH & "big_buck_bunny.mp4"
-- set callback that is triggered when video is ready to play
$.avmedia.setReadyStatusChangeCallback(#videoReadyForDisplay)
-- set callback that is triggered when video window was closed
$.avmedia.setWindowClosedCallback(#halt, _movie)
-- open the video window (hidden)
-- videoOpen object me, string pathOrURL, object rect, *stayOnTop, windowMask, overlayFlag, windowTitle
gWindowID = $.avmedia.videoOpen(fn, rect(0,0,0,0), FALSE, $.avmedia.MASK.StandardWin)
end
----------------------------------------
-- @callback
----------------------------------------
on videoReadyForDisplay (status)
monitorRect = _system.desktopRectList[1]
-- test: play with 640*360 at screen center
w = 640
h = 360
x = (monitorRect.width - w)/2
y = (monitorRect.height - h)/2
playRect = rect(x, y, x+w, y+h)
-- show video window
$.avmedia.videoSetRect(playRect)
-- start playing (at default speed)
$.avmedia.videoSetRate(1.0)
-- grab first frame as image
m = new(#bitmap)
captureCurrentVideoFrame (m)
end
----------------------------------------
-- Grabs image of current video frame
-- Usage:
-- m = new(#bitmap)
-- captureCurrentVideoFrame(m)
-- --> member m now contains a bitmap of the curent video frame
----------------------------------------
--on captureCurrentVideoFrame (memRef)
-- r = $.avmedia.videoGetRect()
-- cmd = "/usr/sbin/screencapture -c -R"&r.left&","&r.top&","&r.width&","&r.height
-- $.shell.shell_cmd(cmd)
-- memRef.pasteClipBoardInto()
--end
----------------------------------------
-- Grabs image of current video frame
-- Usage:
-- m = new(#bitmap)
-- captureCurrentVideoFrame(gWindowID, m)
-- --> member m now contains a bitmap of the curent video frame
----------------------------------------
on captureCurrentVideoFrame (memRef)
cmd = "/usr/sbin/screencapture -c -o -l"&gWindowID
$.shell.shell_cmd(cmd)
memRef.pasteClipBoardInto()
end