Flash AS3: (VideoEvent.COMPLETE, completePlay) - listener is triggered before video is completed
I have a flash video using the standard FLV Playback component that comes with Flash. I'm using ActionScript 3 to modify the appearance and set up an event listener. I've set it up to go to a new URL using "externalInterface" when the video completes play. The URL is set in a variable using SWFObject.
On only a few instances (3 people out of 50 - tested using Amazon Turk), people reported being taken directly to the new url, before the video even started playing. It's difficult to repeat the issue, but it did happen to me once. It doesn't have anything to do with cache, since it has been reported on people going to the url for the first time.
Here's the url to the video: http://www.partstown.com/is-bin/INTERSHOP.enfinity/WFS/Reedy-PartsTown-Site/en_US/-/USD/ViewStaticPage-UnFramed?page=tourthetown
Here's the code:
import flash.external.*;
import fl.video.*;
var myVideo:FLVPlayback = ne开发者_如何学运维w FLVPlayback();
var theUrl:String = this.loaderInfo.parameters.urlName;
var theScript:String = this.loaderInfo.parameters.scriptName;
myVideo.source = this.loaderInfo.parameters.videoPath;//"partstown.flv";
myVideo.skin = this.loaderInfo.parameters.skinPath;//"SkinUnderPlayStopSeekMuteVol.swf"
myVideo.skinBackgroundColor = 0xAEBEFB;
myVideo.skinBackgroundAlpha = 0.5;
myVideo.width = 939;
myVideo.height = 660;
myVideo.addEventListener(VideoEvent.COMPLETE, completePlay);
function completePlay(e:VideoEvent):void {
myVideo.alpha=0.2;
ExternalInterface.call(theScript);
}
addChild(myVideo);
Why would the listener be triggered before the event complete? How can I fix it?
Thanks!
from what I was ablr to find you would need to check to see the initial stopped state of the video.
This snippet will detect when the video has reached a "stopped" state. The "playbackBegun" boolean is used as a way to ignore the first "stopped" state, which occurs before the video begins it's "playing" state
the code is found here
dreamincode .
From what I understood is that after the video is loaded is has an initial stopped state, which means your fully loaded video triggers the event. thus the video is skipped. I had gone to the link you posted and found that I too was redirected before the video played.
hope this helps a bit. will keep looking to see if there is anything else.
It seems Firefox triggers the COMPLETE when it reaches the end of loaded amount of the video. That is, if the whole video has not been loaded, but it completes the fraction of what has, the listener gets fired. Setting my own progress event, instead of relying on the built "playwhenenoughloaded" seems to have fixed the issue.
Here's the code:
import flash.external.*;
import fl.video.*;
var myVideo:FLVPlayback = new FLVPlayback();
var theUrl:String = this.loaderInfo.parameters.urlName;
var theScript:String = this.loaderInfo.parameters.scriptName;
myVideo.source = this.loaderInfo.parameters.videoPath;//"partstown.flv";
myVideo.skin = this.loaderInfo.parameters.skinPath;//"SkinUnderPlayStopSeekMuteVol.swf"
myVideo.skinBackgroundColor = 0xAEBEFB;
myVideo.skinBackgroundAlpha = 0.5;
myVideo.width = 939;
myVideo.height = 660;
myVideo.autoPlay = false;
myVideo.addEventListener(ProgressEvent.PROGRESS, onLoadProgress);
function onLoadProgress(event:ProgressEvent):void {
var loadedPct:uint = Math.round(100 * (event.bytesLoaded / event.bytesTotal));
trace('waiting...');
if (loadedPct >= 20){
trace(event.bytesLoaded);
trace(loadedPct);
myVideo.play();
trace('Playing');
}
if (loadedPct >= 90){
trace('Ready to Complete');
myVideo.addEventListener(VideoEvent.COMPLETE, completePlay);
}
}
function completePlay(ve:VideoEvent):void {
trace('COMPLETE!!');
myVideo.alpha=0.2;
ExternalInterface.call(theScript);
}
addChild(myVideo);
精彩评论