![](/img/trans.png)
[英]flash as3 netStream video. How to skip 3 seconds forward/backward while playing video?
[英]How to skip video if button is not pressed in AS3 Flash?
我正在AS3中從事視頻廣告自助項目。 影片的長度基本上是10秒。 我設置了一個計時器,該計時器會在5秒鍾后顯示“繼續觀看”按鈕,如果互動,該視頻將繼續播放。 如果沒有,它將在7秒鍾后自動結束視頻。 如果未按下按鈕,如何提示視頻停止播放? 我很困惑。
var baseTimer:Timer = new Timer(5000,1)
var isInteracted:Boolean = false;
baseTimer.addEventListener(TimerEvent.TIMER, testTimer);
btSkip.addEventListener(MouseEvent.CLICK, btSkipvideo);
baseTimer.start();
function btSkipvideo(e:MouseEvent)
{
if (!isInteracted)
{
btSkip.visible = false;
}
else
trace("This is a testing");
}
只需創建另一個計時器即可完成此操作。 所以像這樣:
var baseTimer:Timer;
var timeoutTimer:Timer;
//assuming your btSkip button is a timeline object that is not currently visible
btSkip.addEventListener(MouseEvent.CLICK, btSkipvideo, false, 0, true);
function startVideo():void {
//do whatever you do to start the video
//create the base timer to show the button after 5 seconds
baseTimer = new Timer(5000, 1);
baseTimer.addEventListener(TimerEvent.TIMER, showBtn, false, 0, true); //use weak listener so the timer doesn't stay in memory forever
baseTimer.start();
}
function endVideo(e:Event = null):void {
//do whatever you do to stop the video
}
function showBtn(e:Event):void {
btSkip.visible = true; //or however you decide to show the button
//at this point it's been 5 seconds since the video started to play
//create the other timer to end the video after 2 additional seconds
timeoutTimer = new Timer(2000, 1);
timeoutTimer.addEventListener(TimerEvent.TIMER, endVideo, false, 0, true);
timeoutTimer.start();
}
function btSkipvideo(e:MouseEvent){
if (timeoutTimer) {
//stop the timer so it doesn't end the video
timeoutTimer.stop();
}
btSkip.visible = false; //or however you'd hide the button
}
首先,由於流緩沖的問題,我認為最好使用視頻播放器( FLVPlayback
組件, NetStream
對象...)來獲取執行任何事情的准確時間(5秒和7秒)。 ..但是,僅使用Timer
對象回答您的問題,我認為您只能使用一個Timer
來完成您要尋找的事情:
var timer:Timer = new Timer(1000); // you can set the repeat count to 7 if you want
timer.addEventListener(TimerEvent.TIMER, on_Timer);
function on_Timer(e:TimerEvent): void {
switch (e.target.currentCount) {
5: // 5 seconds, show the "Keep Watching" button
btSkip.visible = true;
break;
7: // 7 seconds, if the timer is always running, so stop the video
stop_the_video();
break;
}
}
function play_the_video(): void {
// start playing your video
timer.start();
}
function stop_the_video(): void {
// stop playing your video
timer.stop();
}
btSkip.addEventListener(MouseEvent.CLICK, btSkipvideo);
function btSkipvideo(e:MouseEvent): void {
timer.stop();
}
希望能對您有所幫助。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.