我正在使用greensock LoaderMax来加载视频文件和声音文件。我复制了尽可能多的代码。视频(s9)正在播放,并且通过视频以一定比例播放,我需要播放另一种声音。
if(s9.playProgress > .1) // This is what I can't get to work
{
s12_sound.playSound(); //This sound won't play at .1 playProgress
}
s9.content.visible = true;
s9.playVideo();
stop();
s9.addEventListener(VideoLoader.VIDEO_COMPLETE, play_s9_loop); //This plays a video once s9 is done.
function play_s9_loop(event:Event):void
{
s9.content.visible = false;
s9_loop.content.visible = true;
s9_loop.playVideo();
}
我猜你不能在playProgress上做一个if()?此外,我在AS3吮吸。
答案 0 :(得分:2)
您应该能够只监听视频上的INIT事件(这通常意味着它已经足够加载以确定视频的持续时间),然后添加AS提示点。
//...after you create your VideoLoader...
myVideoLoader.addEventListener(LoaderEvent.INIT, initHandler);
myVideoLoader.load();
function initHandler(event:LoaderEvent):void {
myVideoLoader.addASCuePoint( myVideoLoader.duration * 0.1, "myLabel" );
myVideoLoader.addEventListener(VideoLoader.VIDEO_CUE_POINT, cuePointHandler);
}
function cuePointHandler(event:LoaderEvent):void {
trace("Hit the cue point " + event.data.name);
s12_sound.playSound();
}
还要确保预先加载s12_sound,以便在需要时可以播放。否则,您可以随心所欲地调用playSound()并且它不会发生:)
答案 1 :(得分:1)
我之前没有使用过这个课程,但在阅读完文档之后,看起来你可以这样做: http://www.greensock.com/as/docs/tween/com/greensock/loading/VideoLoader.html
var mid:Number = s9_loop.duration/2; //get the midpoint using the duration property
s9_loop.addASCuePoint(mid, "middle") //using addASCubePoint to add a cuepoint to the midpoint of the video
s9_loop.addEventListener(VideoLoader.VIDEO_CUE_POINT, handleMidpoint); //listen for the cuepoint
处理程序函数内部
protected function handleMidpoint(e:Event):void{
//play your sound
}