50

I am currently working on a Flash webplayer with resolution switching functionality. I am trying to make use of the NetStream class's play2() function in Actionscript.

The problem I am running into is that the videos don't change quickly. For those familiar with the play2() function I believe that the player is performing a "standard switch" rather than a "fast switch."

The documentation says that when the offset parameter is -1, fast switching occurs. What actually happens, though is once the "NetStream.Play.Transition" event is received, the player waits until the time denoted by ns.time + ns.bufferLength has been reached, before performing the switch.

I thought fast switching cleared the buffer, but on a check to ns.backbufferlength, I found that everything is still cached. Also it mentions: "When offset is -1, the switch occurs at the first available keyframe after netstream.time + 3," which is why I am confused.

Any help/insight on this matter would be much appreciated.

Here is a snippet of code describing what is going on (newStream() is called when a user clicks to change to a new resolution, youtube style):

public function newStream(address:String):void
{
    var opts:NetStreamPlayOptions = new NetStreamPlayOptions();
    opts.streamName = address;
    opts.transition = NetStreamPlayTransitions.SWITCH;
    opts.offset = -1;
    ns.play2(opts);
}

private function nsCallback(event:NetStatusEvent)
{
    switch(event.info.code)
    {
        case "NetStream.Play.Transition":
        {
            trace("Current time (on Transition): " + 
                  ns.time, "Buffer: " + ns.bufferLength);
            var estTime:Number = ns.time + ns.bufferLength;
            trace("Estimated Completion Time: " + estTime);
            break;
        }
    }
}
Praveen Vinny
  • 2,372
  • 6
  • 32
  • 40
funseiki
  • 9,167
  • 9
  • 36
  • 59
  • 4
    Have you looked into a **framework** that does *Dynamic Stream Switching* for you? I use one because it allows me to focus on other things (one less thing I have to worry about). OSMF will do a lot, but not DSS for http streams (yet). However, OVP (Akamai HDCore) will even do DSS for http streams to flash. Good luck! – Jacksonkr Aug 07 '11 at 20:23
  • 1
    I found a few while Googling for an answer to my question, but I was a building a pretty specific player (there are a few extra features that I added to it). Also, since I already had the majority of the player done (minus the "smooth" transitioning), I was hoping for a solution. As of now, I've made do with adding a little "loading" icon anytime there is a stream switch, though I have left the functionality available in case I ever do find an answer for this issue. – funseiki Aug 09 '11 at 04:00
  • instead of a switching the video of same content can this be used to switch to a different video stream? – Aditya P Jan 24 '12 at 10:45
  • Have you tried these "Best practices" from Adobe? http://help.adobe.com/en_US/flashmediaserver/devguide/WS3f305989b15d10dc44125e8c12a5fb2d1da-8000.html – Raohmaru Sep 11 '12 at 15:52
  • 4
    Pay attention to the video streams you are trying to play and switch. They need to be carefully encoded, especially keyframe value should be set to the same value for all videos/streams. Setting this property depends on if you are playing live or VOD media, or the software you are encoding with. – Max Golovanchuk Oct 01 '12 at 12:37
  • @MaxGolovanchuk is right. Sometimes keyframes can be pretty far apart. I've seen 10 or 15 seconds. – Matt Nov 30 '12 at 17:08
  • @MaxGolovanchuk There may be keyframe mismatch issue, but for some reason, it still only transitions when the playhead hits the end of the buffer (otherwise, it would transition on the next key frame interval, regardless of what was in the buffer). – funseiki Dec 13 '12 at 16:08

2 Answers2

1

As the Documentation says: "The default value of offset is -1, which defaults the switching behavior to standard. In this mode, the server determines a good transition point between the streams forward in time from the point it receives the switch call, and switches at that point."

So you have to change the 'offset' parameter to a value higher than the current playback time (Netstream.time). If the value is less, a NetStream.Play.Failed status event is sent.

  • What part of the documentation says offset = -1 is standard switch mode? What I'm looking says this: "The default value of offset is -1, which is fast switch mode." You can find this quote [here](http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/NetStreamPlayOptions.html#offset). Second paragraph, first sentence under "Fast Switch" – funseiki Dec 29 '12 at 22:46
  • Also, according the doc, it is not required to set 'offset' to a value greater than the current playback time, because, by default, "When offset is -1, the switch occurs at the first available keyframe after netstream.time + 3" – funseiki Dec 29 '12 at 22:51
  • @funseiki - That is a sort of strange, because I use an offline Documentation (for flash cs5) and it has written "The default value of offset is -1, which defaults the switching behavior to standard." whereas I checked the online documentation and I saw that it has written "The default value of offset is -1, which is fast switch mode." Check it out: https://www.dropbox.com/s/2qm143e6mc93byl/offline.png –  Dec 30 '12 at 11:10
  • Odd - have you tested this to see if it works? I remember trying to set the offset parameter explicitly and it not working as expected (the buffer didn't clear when the playhead reached the expected time) – funseiki Dec 31 '12 at 05:29
1

It could be that the server is trying to find the nearest i-frame to the current offset and that takes time. If you know what FPS is and the time between two i-frames is you could try to seek to a time very near to the next or previous i-frame, that would speed up the search and serving.

more info on i-frame: http://en.wikipedia.org/wiki/Video_compression_picture_types