6 Replies Latest reply on Aug 7, 2013 9:11 PM by Da嗒_Sunny

    switchDynamicStreamIndex doesn't work

    punknrollDD Level 1

      Hi, i try to set the StreamingItem of a video manually. But in my code the method switchDynamicStreamIndex has no impact at all. The index always stays at position 0. What am I doing wrong?


      Here is my code:



      mediaFactory = new DefaultMediaFactory();
      mediaPlayer = new MediaPlayer();
      mediaContainer = new MediaContainer();
      var netLoader:NetLoader = new RTMPDynamicStreamingNetLoader();
      var dsResource:DynamicStreamingResource = new DynamicStreamingResource('rtmp://xxxxxxxxxx/playlistx/');
      dsResource.streamItems.push(new DynamicStreamingItem("Bike_lq", 400 ));
      dsResource.streamItems.push(new DynamicStreamingItem("Bike_mq", 600 ));
      dsResource.streamItems.push(new DynamicStreamingItem("Bike_hq", 1500 ));


      mediaElement=new VideoElement(dsResource, netLoader);




      try {
      } catch(error:RangeError) {
          trace("Range Error: " + error);
      } catch(error:IllegalOperationError) {
          trace("illegaloperatorError: " + error);
      } finally {


      var streamMsg:String = "Current streaming profile index: " + mediaPlayer.currentDynamicStreamIndex + " of " + mediaPlayer.maxAllowedDynamicStreamIndex;
      streamMsg = "Current bitrate = " + mediaPlayer.getBitrateForDynamicStreamIndex(mediaPlayer.currentDynamicStreamIndex) + "kbps";



      The output is always: Current streaming profile index: 0 of 2


      Thanx for your help!

        • 1. Re: switchDynamicStreamIndex doesn't work
          bringrags Level 4

          Stream switching is not a synchronous operation, as typically the player needs to eat through the existing buffer.  The current stream index will remain at its previous value until the switch completes.  You should try listening for the switchingChange event.  You'll get one when the switch begins (switching == true), and another one when the switch completes (switching == false).

          • 2. Re: switchDynamicStreamIndex doesn't work
            punknrollDD Level 1

            Hi, thanx for your help.


            I now I listen to the event, but the switch never finishes...


                                trace('ist dynamic');
                                dynamicStreamTrait = mediaElement.getTrait(MediaTraitType.DYNAMIC_STREAM) as DynamicStreamTrait;
                                dynamicStreamTrait.addEventListener(DynamicStreamEvent.SWITCHING_CHANGE, onTestChange);



            private function onTestChange(evt:DynamicStreamEvent):void
                            if(evt.switching == true)
                                trace ('switching starts');
                                trace('switching finished');


            'switching finished' is never traced. what can be wrong? Thanx.

            • 3. Re: switchDynamicStreamIndex doesn't work
              bringrags Level 4

              That's almost certainly a bug.  We've seen this occur before when the encoded file's bitrate vastly exceeds available bandwidth, and have a bug filed for that case against FMS.  But I'm not sure whether you're running into the same thing.


              Could you log a bug here?




              If you don't want to post your RTMP links publicly, feel free to email them to me directly (briggs at adobe dot com).

              • 4. Re: switchDynamicStreamIndex doesn't work
                punknrollDD Level 1

                Hi, i still couldn't solve the problem. Has anybody got a working sample for switching the streams manually with actual sprite?


                thanx Andi

                • 5. Re: switchDynamicStreamIndex doesn't work
                  punknrollDD Level 1

                  Brian told me, that FMS in version 3 doesn't support server-side dynamic  stream switching. So hopefully I can upgrade.


                  Thanks a lot to Brian for your great support.



                  • 6. Re: switchDynamicStreamIndex doesn't work
                    Da嗒_Sunny Level 1

                    I get the same problem.

                    Here is an email that I have send to dev@flex.apache.org.

                    Hope to can help you,



                    Using OSMF2.0 to stream a smil title.

                    Add the MediaPlayerCapabilityChangeEvent.IS_DYNAMIC_STREAM_CHANGE event listener, after the event dispatch then add the DynamicStreamEvent.SWITCHING_CHANGE event listener.

                    The bitrate info can be report, normal. But after I add the SMPTE-TT plugin and load it like this:

                    var pluginResource:MediaResourceBase = new PluginInfoResource(new SMPTETTPluginInfo);mediaFactory.loadPlugin(pluginResource);


                    The title can be stream correct and the quality of the video can be set by the bandwidth, but only the DynamicStreamEvent.SWITCHING_CHANGE event can not be dispatch, so I can't get the current bitrate info.

                    I debug it in the OSMF source code and find the issue in the org.osmf.elements.compositeClasses.ParallelDynamicStreamTrait class line 323





                    onSwitchingChange function that the numChildrenSwitching property always 0, so it can not call the setSwitching function and can not dispatch DynamicStreamEvent.SWITCHING_CHANGE event.

                    So, I add some changes from line 333 to line 336 and it has be fix: