Question

Goodmorning,

I'm working on a video flash player to stream. What I want to do, is to display the total time of the stream and not the time since the user is watching the stream. I have a problem now, is that when I pause then play the video, the current time restarts. Do you have any ideas to fix my problem and to solve the other one? :)

**I'm using NetStream

Était-ce utile?

La solution

Alright, for the first problem, what you want to do is to setup a function that receives the MetaData of the video and save that value somewhere.

First, when you create your NetStream Object, you need to add a Client to the NetStream that references the function onMetaData.

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
}

Now with the duration value you get the total play time of the movie that is currently playing with that NetStream Object.


You can solve your second problem in a number of ways, for example:

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

Simply keep a Boolean Variable called pause that keeps track if the video is currently playing or not.

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;
    }
}

Autres conseils

You have to extract the information from the meta data of the file.

Thank you for you answers :).

DodgerThud, I tried your solution concerning my second problem this morning. I tried your solution and I've got this : duration : NaN. If I understand well, my problem is that I don't have the metadata of the stream...

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

Those lines are on the onMetaData function.

Thank you for helping me. Have a nice day.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top