5 Replies Latest reply on Apr 29, 2010 7:16 PM by shrelp

    Minimalist set video size example

    shrelp

      OSMV is very thick so so I'm trying to put a series of minimalist tutorials and again I'm stuck with something that should be dead simple.

       

      I have a VideoElement that I added to a MediaPlayer.  Now now do I set the size of the video?

       

      private function handle_elementLoaded(e:MediaFactoryEvent):void
                {
                     mediaPlayer = new MediaPlayer(e.mediaElement);
                     mediaPlayer.addEventListener(MediaPlayerStateChangeEvent.MEDIA_PLAYER_STATE_CHANGE, handle_stateChange);
                }
                /**
                 * 5.  mediaPlayer.displayObject is no lonager null so we an add it to the stage.  
                 */          
                private function handle_stateChange(e:MediaPlayerStateChangeEvent):void
                {
                     trace("handle_stateChange",e.state);
                     if (e.state == MediaPlayerState.READY)
                            {
                          addChild(mediaPlayer.displayObject);
                            } 
                }
      

        • 1. Re: Minimalist set video size example
          shrelp Level 1

          And I wanted to size the video without including 20 layout classes like the other examples.  I'm trying to make some dead simple tutorials.

          • 3. Re: Minimalist set video size example
            RyanOConnell Level 2

            Repost Below.

            • 4. Re: Minimalist set video size example
              RyanOConnell Level 2

              This is relatively simple.  We've introduced the MediaPlayerSprite to take care of most of the headache for you:

               

               

              public function MediaPlayerSpriteSample()

              {

              //Neccesary to prevent the MPS from scaling via ScaleX and ScaleY.

              stage.scaleMode = StageScaleMode.NO_SCALE;

              stage.align = StageAlign.TOP_LEFT;

               

              // Create the container class that displays the media.

              mps = new MediaPlayerSprite();

               

              addChild(mps);

              stage.addEventListener(Event.RESIZE, onResize);

              mps.resource = new URLResource(REMOTE_AKAMAI_STREAM);

               

              //Update the MPS to the initial size.

              onResize();

              }

              private function onResize(event:Event = null):void

              {

              mps.width = stage.stageWidth;

              mps.height = stage.stageHeight;

              }

              • 5. Re: Minimalist set video size example
                shrelp Level 1

                Well MediaPlayerSprite as a great API but I can't get it actually size the video player. 

                Am I doing something wrong here? 

                mps.width = 10;

                 

                I also tried adjusting the width at a later time and couldn't get it to work.

                 

                private function onPluginLoaded(e:MediaFactoryEvent):void

                {

                var resource:URLResource = new StreamingURLResource(assetId);

                mediaFactory.addEventListener(MediaFactoryEvent.MEDIA_ELEMENT_CREATE, handle_elementLoaded);

                mediaElement = mediaFactory.createMediaElement(resource);

                mediaElement.addEventListener(MediaErrorEvent.MEDIA_ERROR, onMediaError);

                 

                mps = new MediaPlayerSprite();

                mps.addEventListener(MediaPlayerStateChangeEvent.MEDIA_PLAYER_STATE_CHANGE, handle_stateChange);

                mps.resource = resource;

                mps.scaleMode = ScaleMode.NONE;

                mps.width = 10;

                mps.height = 100;

                addChild(mps);

                }