开发者

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

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开发者_C百科.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);
    }
}}


I don't know much about flex but i've used an OSMF player called the StrobeMediaPlayback and embedded it onto a html page. There's a javascript bridge which you can call using the ExternalInterface.call() function in actionscript (within the player code).

So I wrote a javascript function to resize the swf (can be done easily using jquery) and called it from actionScript whenever the video had to scale.

See if this helps you.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜