Reset FLVPlayback component for playback with same source
I'm using the same FLVPlayback component to play many page transition videos thro开发者_如何学编程ughout a large flash site I'm building. On each transition, I'm setting the component's source using myFLVPlayback.source
and listening for the fl.video.VideoEvent.READY
event before proceeding with each page transition. This works fine as long as the transition between every pair of pages uses a different video.
Unfortunately, I'm running into a problem when the same page-to-page transition video needs to get invoked for two consecutive transitions. When playing the same video twice in a row, setting the source
property of the component to the value it already has doesn't seem to do anything, meaning that my listeners for fl.video.VideoEvent.READY
never fire. I could do something hackish like setting the source
to a tiny, never-used-elsewhere FLV before setting it to the FLV that I'm actually using for the transition as a means of "resetting" the component, but I'd like to know what best practices are in a situation like this (insofar as best practices with something like the FLVPlaybackComponent can be discussed with a straight face).
I've perused the livedocs for the component but came up empty-handed, and manually using NetStream, NetConnection, and Video objects at this late stage isn't really an option.
I would suggest having a harness that checks whether the URL you are about to play is the same as for the previous transition, and if it is, just seek(0) (i.e. rewind the video) instead of resetting source. Resetting the source might force the video to reloed (e.g. if browser cache is disabled) and that is probably not what you want anyway.
if (myFlvPlayback.source == nextTransitionUrl) {
myFlvPlayback.seek(0);
startTransition();
}
else {
myFlvPlayback.source = nextTransitionUrl;
// The "ready" event will fire, and your event handler will start playback
}
Have a look at the FLVPlayback.seek() method.
Cheers
Looks like this one has been solved for awhile, but I thought I'd chime in anyway. To exactly emulate the behavior you described, you could check to see if the source is == to the next URL, then just call dispatchEvent on the flvPlayback instance directly. That way it behaves like it would if the URL was different and the only manual intervention you've had to code in would be just checking if the URLs are ==.
精彩评论