Jump to content
Search Community

VideoLoader - keep 2 looping videos in sync?

Cloud Media Lab test
Moderator Tag

Recommended Posts

I have two videos of identical length that I need to play in sync.

 

Occasionally they do loop in sync but are most often offset by some small amount. Unfortunately this is very noticeable in my application.

 

example:

video1.addEventListener(VideoLoader.VIDEO_COMPLETE, function():void {
video1.gotoVideoTime(0, true);
video2.gotoVideoTime(0, true);
});

 

Any suggestions, please?

Link to comment
Share on other sites

The challenge is that the way Flash handles video involves a buffering process which can be a bit unpredictable. Imagine having two browser windows open that are both set to play the same YouTube video and you click the "reload" button on the browser simultaneously - the videos probably wouldn't be perfectly synced. The processor and network and memory all have to work together and there can be little hang-ups in any of those.

 

One thing you could try is to pause both videos (when you want to loop) and then gotoVideoTime(0) for both and listen for the BUFFER_FULL event to be dispatched for both of them. Once you receive BOTH, you can playVideo().

Link to comment
Share on other sites

Great suggestion, it appears to be working well.

 

Thanks! Snippets of code...

 

 

 

video1buffer = new NativeSignal(video1, VideoLoader.VIDEO_BUFFER_FULL, LoaderEvent);
video2buffer = new NativeSignal(video2, VideoLoader.VIDEO_BUFFER_FULL, LoaderEvent);
video1buffered = false;
video2buffered = false;

video1.addEventListener(VideoLoader.VIDEO_COMPLETE, function(event:LoaderEvent):void {
videoSeek(0);
});

videoSeek(0);



public function videoSeek(time:Number):void {
//Cc.info( "videoSeek("+time+")" );
video1buffered = false;
video2buffered = false;
video1.pause();
video2.pause();
video1buffer.addOnce(videoBuffered);
video2buffer.addOnce(videoBuffered);
video1.gotoVideoTime(time);
video2.gotoVideoTime(time);
}

public function videoBuffered(event:LoaderEvent):void {
if (event.target == video1) video1buffered = true;
if (event.target == video2) video2buffered = true;
if (video1buffered && video2buffered) {
video1.playVideo();
video2.playVideo();
}
}

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...