流的总时间 - 视频Flash Player AS3

时间:2013-11-29 09:27:43

标签: actionscript-3 flash timer stream netstream

早安,

我正在制作视频Flash播放器以进行流式传输。我想要做的是显示流的总时间,而不是自用户观看流以来的时间。 我现在有一个问题,就是当我暂停然后播放视频时,当前时间重新启动。 你有什么想法来解决我的问题并解决另一个问题吗? :)

**我正在使用NetStream

3 个答案:

答案 0 :(得分:1)

好的,对于第一个问题,你要做的是设置一个接收视频元数据并在某处保存该值的函数。

首先,在创建NetStream对象时,需要将一个Client添加到引用onMetaData函数的NetStream中。

var ns:NetStream;   //your NetStream Object
var client:Object = new Object(); //Create an Object that represents the client
client.onMetaData = onMetaData; //reference the function that catches the MetaData of the Video
ns.client = client;             //assign our client Object to the client property of the NetStream
                                //Once MetaData is available, it'll call onMetaData with all of the information

function onMetaData(metaData:Object):void
{
    duration = metaData.duration;   //duration is the variable that is supposed to total length of the video
}

现在使用duration值可以获得当前正在使用该NetStream对象播放的电影的总播放时间。


您可以通过多种方式解决第二个问题,例如:

  • pause()和resume()
  • pause()和player('currentTime')

只需保留一个名为“暂停”的Boolean变量,即可跟踪视频当前是否正在播放。

var paused:Boolean = false;  //assuming the video is currently playing
var currentTime:Number = 0;  
var button:Button;    //some kind of play/pause button
button.addEventListener(MouseEvent.CLICK,onButtonClick);

function onButtonClick(event:MouseEvent):void
{
    if(paused)
    {
        paused = false;
        ns.resume();
        //ns.play(currentTime)   //this also works
    }
    else
    {
        paused = true;
        ns.pause();
        currentTime = ns.time;
    }
}

答案 1 :(得分:0)

您必须从文件的元数据中提取信息。

答案 2 :(得分:0)

谢谢你的回答:)。

道奇德,我今天早上尝试了解决第二个问题的方法。我尝试了你的解决方案,我得到了这个:持续时间:NaN。如果我理解得很好,我的问题是我没有流的元数据......

if(isLiveStream == false) {
            if(title == preroll || Number(duree) <= 0) {
                duration=infoObject.duration+timeOffset;
            } else {
                duration=Number(duree);
            }
        }

这些行在onMetaData函数上。

感谢您帮助我。 祝你有愉快的一天。