Video Events
How can I handle video events in the script?
For example, when new chapter started. Or when certain frame reached.
How can I handle video events in the script?
For example, when new chapter started. Or when certain frame reached.
Listen to the chapter event for chapter changes -- if you have the spec, the events are defined in Z.6.2-1
Example code:
"chapter", handleChapter, false);addEventListener(
function
handleChapter(evt)For knowing when certain frames are reached, you can either use scheduled events (in the playlist) or you can have cues in the markup bound to the title clock that fire events on a given frame.
For stopping at certain frames, here is a bit of playlist:
<ScheduledControlList>
<Event id="Capture" titleTime="00:01:30:00" />
</ScheduledControlList>
and here is some Script to handle it (which pauses, captures the video frame, then resumes):
application.addEventListener( "scheduled_event", OnScheduledEvent, false )
function VideoMainCaptureCallback(i,uri)
{
Player.playlist.play();
}
function PlayerVideoMainCapture(filename)
{
try
{
Player.video.main.capture(filename,VideoMainCaptureCallback);
}
catch (ex)
{
}
}
function OnScheduledEvent(evt)
{
if (evt.id == 'Capture')
{
Player.playlist.pause();
PlayerVideoMainCapture("file:///filecache/test.cvi");
}
}
Shouldn't it be:
tryTo match the signature specified in Z.10.19.3?
And also, I don't understand why the interface for that callback. Why pass the uri and status?
try
{
Player.video.main.capture(filename,VideoMainCaptureCallback);
}
is the correct one.
VideoMainCaptureCallback is the callback function. No need of passing parameters as this function is called internally.
function VideoMainCaptureCallback(status,uri)
{
// you can use status and uri to check whether captured image is stored
//in respective uri successfully or failed
if(status == Player.Finished)
{
//capture succeeded
}
Player.playlist.play();
}
Andy Pennell MSFT wrote:
For stopping at certain frames, here is a bit of playlist:
<ScheduledControlList>
<Event id="Capture" titleTime="00:01:30:00" />
</ScheduledControlList>and here is some Script to handle it (which pauses, captures the video frame, then resumes):
application.addEventListener( "scheduled_event", OnScheduledEvent, false )
function VideoMainCaptureCallback(i,uri)
{
Player.playlist.play();
}function PlayerVideoMainCapture(filename)
{
try
{
Player.video.main.capture(filename,VideoMainCaptureCallback);
}
catch (ex)
{
}
}
function OnScheduledEvent(evt)
{
if (evt.id == 'Capture')
{
Player.playlist.pause();
PlayerVideoMainCapture("file:///filecache/test.cvi");
}
}
I tried a simple version of this and cannot get it to work. No pause at 10 seconds.
## js ## function OnScheduledEvent(evt) { ## playlist ## <Title titleNumber="3" titleDuration="00:04:18:00" id="greenday" displayName="Green Day" onEnd="robthomas">
if (evt.id == "ev1") {
Player.playlist.pause();
}
}
addEventListener("ScheduledEvent", OnScheduledEvent, false);
<PrimaryAudioVideoClip titleTimeBegin="00:00:00:00" titleTimeEnd="00:04:17:00"
src="file:///dvddisc/HVDVD_TS/GreenDay_AmericanIdiot_700.wmv" dataSource="Disc">
<Video track="1" />
<Audio track="1" streamNumber="1" />
</PrimaryAudioVideoClip>
<ChapterList>
<Chapter titleTimeBegin="00:00:00:00" />
</ChapterList>
<ScheduledControlList>
<Event id="ev1" titleTime="00:00:10:00" />
</ScheduledControlList>
</Title>
What's odd is I just ran the HDValidator and it complains the ScheduledControlList is not an allowed Element for Title! However the spec clearly says it is. I will post this question in a new thread.
Bryan Kilian - MSFT wrote:
It needs to be "scheduled_event", not "ScheduledEvent" in your AddEventListener?
Ok that was it - THANKS!
But why? Where in the spec does it define the name of the scheduled event parameter?
Table 8.3.1-1 just calls it "Scheduled".