【问题标题】:How to display mp4 then pause and replay in Flash CC如何在 Flash CC 中显示 mp4 然后暂停和重播
【发布时间】:2014-11-04 05:19:47
【问题描述】:

我正在恢复一个简单的横幅,其中我们使用 FLV 电影和以下代码使用 setInterval 让电影暂停然后再次播放。这是一部简单的蝴蝶电影,它扇动翅膀,然后回到静止状态。

似乎在最近的 Flash 版本中不鼓励使用 FLV,所以我想知道如何播放电影,然后使用 setInterval 暂停,然后重播。

这是在基于帧的动画中的时间轴上使用 FLV 但不适用于导入的 .mp4 时的工作 AS3:

stop(); 
function timesUp()
{ 
gotoAndPlay(1,"Scene 1"); 
clearInterval(itv); 
} 
var itv=setInterval(timesUp, 15000);

建议的新方法是否使用单帧电影来加载和播放 mp4,然后使用 setInterval 作为计时器来重播?

我找不到任何以这种方法为例的教程。

我确实阅读了 Adob​​e 网站上的教程,但以下内容没有加载和播放电影 (morpho.mp4)

var nc:NetConnection = new NetConnection(); 
nc.connect(null);
var vid:Video = new Video(); 
addChild(vid);
var ns:NetStream = new NetStream(nc); 
ns.addEventListener(NetStatusEvent.NET_STATUS,netStatusHandler); 
ns.addEventListener(AsyncErrorEvent.ASYNC_ERROR, asyncErrorHandler); 

function netStatusHandler(event:NetStatusEvent):void 
{ 
// handle netStatus events, described later 
} 

function asyncErrorHandler(event:AsyncErrorEvent):void 
{ 
// ignore error 
}
vid.attachNetStream(ns);

ns.play("morpho.mp4");

【问题讨论】:

  • 我测试了你的代码,它没有问题。你能把trace(event.info.code)加到netStatusHandler,可能是因为你的视频没有找到。
  • akmzo - 你是对的。谢谢你。我添加了显示 .mp4 与电影不在同一/根目录中的跟踪。它虽然占据了整个舞台,但仍然可以显示,并将下一个问题转向如何整合 setInterval 和 replay?
  • 我试着做你想要的。

标签: actionscript-3 flash


【解决方案1】:

试试这个:

import flash.utils.Timer
import flash.events.TimerEvent

var video_playing:Boolean = false, 
    timer:Timer,
    nc:NetConnection,
    ns:NetStream,
    video:Video,
    video_name:String = 'video.mp4'

nc = new NetConnection()
nc.connect(null)

ns = new NetStream(nc)
ns.addEventListener(NetStatusEvent.NET_STATUS,netStatusHandler); 
ns.addEventListener(AsyncErrorEvent.ASYNC_ERROR, asyncErrorHandler); 

function netStatusHandler(event:NetStatusEvent):void {      
    switch (event.info.code){
        case 'NetStream.Play.Start' :
            if(timer.currentCount == 0){
                timer.start()
            }
        break       
    }   
} 
function asyncErrorHandler(event:AsyncErrorEvent):void { 
}

video = new Video(135, 135) // set the size of video to 135x135px
video.x = 165               // set the left of video to 300 - 135 = 165px
video.y = 0                 // set the top of video to 0
video.attachNetStream(ns)
addChild(video)

timer = new Timer(1000, 3) // 3 seconds, just for example
timer.addEventListener(TimerEvent.TIMER_COMPLETE, timer_on_Complete)
function timer_on_Complete(e:TimerEvent){
    if(video_playing){
        video_playing = false
        ns.close()
    } else {
        start_video()
    }
    timer.reset()
    timer.start()
}

start_video()

function start_video(){
    ns.play(video_name)
    video_playing = true
}

【讨论】:

  • akmozo - 完美运行。谢谢。问:mp4 是 135 x 135,位于 300 x 135 舞台的右侧。我在时间轴上的左侧有一个徽标,但现在 mp4 覆盖了它。我应该探索哪些代码来了解如何调整 mp4 的大小和位置?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-04-17
  • 2017-01-30
  • 2022-06-12
  • 1970-01-01
  • 2014-03-31
  • 1970-01-01
相关资源
最近更新 更多