views:

464

answers:

4

I've created a player for a client in the past using their LimeLight server to stream videos and not had an issue before, however for a new client using different LimeLight server, the videos seem to be ending 3-4 secs too early.

My traces on 3 vastly different videos I tested:

metadata duration = 32        // 32 secs long, ends at 27
Stop [27.350 seconds] = 4.65 

metadata duration = 17        // 17 secs long, ends at 12
Stop [12.852 seconds] = 4.148

metadata duration = 258       // 258 secs long, ends at 255
Stop [255.861 seconds]

In the video players I check for NetStream.Play.Stop then put a 'reset' type function in there. This function however triggers too early due to this strange bug. Has anyone have seen this before?


private function netStatusHandler(event:NetStatusEvent):void 
    {
        trace("connected is: " + nc.connected );

        switch (event.info.code) 
        {
            case "NetConnection.Connect.Success":
                trace("Connected");
                connectStream();
                break;

            case "NetStream.Play.Start":
                trace("********** Start [" + ns.time.toFixed(3) + " seconds]");
            break;

            case "NetStream.Play.Stop":
                trace("‹ ----------- Playback has stopped. ----------- ›");
                trace("Stop [" + ns.time.toFixed(3) + " seconds]");
                if (nsBuffering){ removeChild(bufferAni); }
                nsBuffering = false;
                videoStatus = "NotPlaying";
                resetVideo(); //<- Video ends so go back to start
                // ^ This triggers too early
            break;
        }
    }

The only work-around I see for this is saving the initial number I get from the metadata duration, and running a timer to constantly check for when the current ns.time matches metadata and then run my reset function.

+4  A: 

I FOUND THE FIX!

http://www.wildform.com/support/tutorials/loopingFLVs/

I had to put in a check first when the netstream hit play.stop, then call my reset function when the buffer was empty...

The code on the site is AS2, but I converted it to AS3:

.

private function netStatusHandler(event:NetStatusEvent):void 
    {
        trace("connected is: " + nc.connected );

        switch (event.info.code) 
        {
            case "NetConnection.Connect.Success":
                trace("Connected");
                connectStream();
                break;

            case "NetStream.Buffer.Empty":
                trace("‹ ----------- Buffer is Empty! ----------- ›");
                if (nsBuffering){ removeChild(bufferAni); }
                nsBuffering = false;

                if (videoFinished) // < Now I can run my reset
                {
                    resetVideo();
                    videoFinished = false;
                }

            break;

            case "NetStream.Buffer.Full":
                trace("‹ ----------- Buffer is FULL! ----------- ›");
                if (nsBuffering){ removeChild(bufferAni); }
                nsBuffering = false;
            break;

            case "NetStream.Buffer.Flush":
                trace("Data has finished streaming, remaining buffer will be emptied.");
                videoStatus = "NotPlaying";
            break;

            case "NetStream.Play.Stop":
                trace("‹ ----------- Playback has stopped. ----------- ›");

                videoFinished = true; // < This first
            break;
        }
    }
Leon
thanks you for this, ive had the same problem!
daidai
woot glad it helped you :)
Leon
A: 

Great Fix.Thanks.

john
thanks :) please up vote the question if you like it, makes it easier for other Flash guys to find
Leon
A: 

THANKS: Excellent FIX

SHAHAB KHAN
A: 

Good man thanks - this has been bugging me (and the rest of the Flash world, it seems) for too long - great work!

Chris Gannon