Skip to content

Instantly share code, notes, and snippets.

@ghinch
Created April 12, 2010 06:44
Show Gist options
  • Save ghinch/363329 to your computer and use it in GitHub Desktop.
Save ghinch/363329 to your computer and use it in GitHub Desktop.
package
{
import flash.display.Sprite;
import flash.events.*;
import org.osmf.media.*;
import org.osmf.layout.LayoutMetadata;
import org.osmf.containers.MediaContainer;
public class MyVideoPlayer extends Sprite
{
public function MyVideoPlayer()
{
mediaFactory = new DefaultMediaFactory();
mediaPlayer = new MediaPlayer();
mediaContainer = new MediaContainer();
mediaContainer.addEventListener('added', loadMedia);
addChild(mediaContainer);
}
private var mediaFactory:MediaFactory;
private var mediaElement:MediaElement;
private var mediaPlayer:MediaPlayer;
private var mediaContainer:MediaContainer;
private var flashVars:Object;
private function loadMedia(e:Event):void
{
mediaContainer.removeEventListener('added', loadMedia);
flashVars = loaderInfo.parameters;
mediaElement = mediaFactory.createMediaElement(new URLResource(flashVars.file));
var layout:LayoutMetadata = new LayoutMetadata();
layout.width = Number(flashVars.width);
layout.height = Number(flashVars.height);
mediaElement.addMetadata(LayoutMetadata.LAYOUT_NAMESPACE, layout);
mediaPlayer.media = mediaElement;
mediaContainer.addMediaElement(mediaElement);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment