How can I scale an OSMF player in ActionScript 3/Flex

Posted by Greg Hinch on Stack Overflow See other posts from Stack Overflow or by Greg Hinch
Published on 2010-04-14T05:59:40Z Indexed on 2010/04/14 6:03 UTC
Read the original article Hit count: 404

Filed under:
|
|
|

I am trying to create a simple video player SWF using the open source media framework in Flex 4. I want to make it dynamically scale based on the dimensions of the video, input by the user. I am following the directions on the Adobe help site, but the video does not seem to scale properly. Depending on the size, sometimes videos play larger than the space allotted on the webpage, and sometimes smaller. The only way I have been able to get it to work properly is by including a SWF metadata tag hardcoding the width and height, but I can't use that if I want to make the player dynamically sized. My code is :

package { 
import flash.display.Sprite;
import flash.events.Event;

import org.osmf.media.MediaElement;
import org.osmf.media.MediaPlayer;
import org.osmf.media.URLResource;
import org.osmf.containers.MediaContainer;
import org.osmf.elements.VideoElement;
import org.osmf.layout.LayoutMetadata;

public class GalleryVideoPlayer extends Sprite { 
    private var videoElement:VideoElement; 
    private var mediaPlayer:MediaPlayer;
    private var mediaContainer:MediaContainer;

    private var flashVars:Object;

    public function GalleryVideoPlayer() {
        if (stage) init();
        else addEventListener(Event.ADDED_TO_STAGE, init);
    }

    private function init(e:Event = null):void {
        removeEventListener(Event.ADDED_TO_STAGE, init);

        flashVars = loaderInfo.parameters;

        mediaPlayer = new MediaPlayer();

        videoElement = new VideoElement(new URLResource(flashVars.file));

        mediaContainer = new MediaContainer();

        var layoutMetadata:LayoutMetadata = new LayoutMetadata();
        layoutMetadata.width = Number(flashVars.width);
        layoutMetadata.height = Number(flashVars.height);

        videoElement.addMetadata(LayoutMetadata.LAYOUT_NAMESPACE, layoutMetadata);

        mediaPlayer.media = videoElement;
        mediaContainer.addMediaElement(videoElement); 

        addChild(mediaContainer);
    }
}}

© Stack Overflow or respective owner

Related posts about flex

Related posts about actionscript-3