1 Reply Latest reply on Jan 13, 2013 4:06 PM by ymichel

    Iterate stream indexes to retrieve properties from DynamicStreamItems

    bernb7760

      I am developing an application which takes a given URL and plays the media. I pass a URLResource to a DefaultMediaFactory to create the MediaElement used by the MediaPlayer.

       

      What I am trying to do is determine the dimensions of the largest of the streams. I would like to set the player to display at this size.

       

      I am currently trying to do this by registering to receive NUM_DYNAMIC_STREAMS_CHANGE events. In this callback, I use MediaElement.getTrait to retrieve the DynamicStreamTrait. I would iterate through the items in the stream to determine the width and height. However I cannot get dsResource from the DynamicStreamTrait, as it is a private property.

       

      Could anybody offer me any pointers on how to achieve my aim?

       

      Thanks, Ben

        • 1. Re: Iterate stream indexes to retrieve properties from DynamicStreamItems
          ymichel Level 1

          The MediaResource is reachable through the MediaElement and the DynamicStreamingItems through the streamItems property :

           

          var mediaElement:MediaElement = new DefaultMediaFactory().createMediaElement(new URLResource(HDS_STREAM_URL));

          mediaElement.addEventListener(MediaElementEvent.TRAIT_ADD, function (event:MediaElementEvent):void

          {

              if (event.traitType == MediaTraitType.DYNAMIC_STREAM)

              {  

                  var dsResource:DynamicStreamingResource = (mediaElement is ProxyElement)

                      ? (mediaElement as ProxyElement).proxiedElement.resource as DynamicStreamingResource

                      : mediaElement.resource as DynamicStreamingResource;

           

           

                  for (var dsIndex:int = 0; dsIndex < dsResource.streamItems.length; dsIndex++)

                  {  

                      if (dsResource.streamItems[dsIndex].width >= MAX_WIDTH)

                      {

                          break;

                      }

                  }

           

           

                  var dsTrait:DynamicStreamTrait = mediaElement.getTrait(event.traitType) as DynamicStreamTrait;

                  dsTrait.autoSwitch = false;

                  dsTrait.switchTo(dsIndex);

                  dsTrait.autoSwitch = true;

              }  

          });

           

           

          var mediaPlayer:MediaPlayer = new MediaPlayer(mediaElement);

           

           

          var mediaContainer:MediaContainer = new MediaContainer();

          mediaContainer.addMediaElement(mediaElement);

          addChild(mediaContainer);