The Simplest Possible OSMF Player
April 14, 2010 in Technology
I'm continuing work on my FITC Toronto talk, 'Standardize Your Flash with Adobe OSMF', and the files to accompany it.
OSMF certainly has features and functionality for hard-core developers to build powerful media-rich experiences. But OSMF also makes basic media player code really easy for those users of Flash who might not consider themselves developers, but who still are comfortable coding on the timeline.
One of the issues with the still nascent, but growing at an impressive rate OSMF documentation, is that almost all the sample code is for users of Flex Builder / Flash Builder -- and all of the sample code for Flash assumes use of external class files.
But using OSMF does not require coding in external class files. So, to illustrate that point, I've gone ahead and modified the simplest possible OSMF video player from Adobe's documentation to code that works on the timeline. Which I'm posting here.
So this is code (OSMF Sprint 10 v0.93) you can paste onto any timeline that will play video with OSMF.
Want to make it stream the video instead of playing it progressively? Point it to an RTMP URL instead, and it will automatically play.
import org.osmf.containers.MediaContainer; import org.osmf.elements.VideoElement; import org.osmf.media.MediaPlayer; import org.osmf.media.URLResource; // Create the container class that displays the media. var container:MediaContainer = new MediaContainer(); //add the MediaContainer instance to the stage addChild(container); // Create the resource to play and point it to the FLV var resource:URLResource=new URLResource("my.flv"); // Create the MediaElement var videoElement:VideoElement=new VideoElement(resource); //add the VideoElement to our container class container.addMediaElement(videoElement); //create the MediaPlayer instance var mediaPlayer:MediaPlayer = new MediaPlayer(); // Set the MediaElement on a MediaPlayer. //Because autoPlay defaults to true, playback begins immediately. mediaPlayer.media=videoElement;
Share and enjoy!
-r





Hi,
I am a big fan of R Blank. A few years back I bought the DMTS traning video he did, called “Inside Macromedia Flash 8″ a very good training DVD. When I got this DVD I had “0″ actionscript training – knew nothing about AS2.0 or Flash for that matter. Struggled through it for months. Now I have Adobe Production Premium CS4.. wow !!
I have just discovered OSMF and it is what I have always wanted.
I am a real estate broker and I want to be able to run my own website that features the videos I have made and edited. I want to be able to change the videos (or add extra ones) without touching the .fla file. I really like the OSMF and I think that R Blank is a great teacher who explains in detail what the heck is going on with AS 3. Great style. Very informative. I have learned quite a bit from him. I have “0″ formal programming experience, just learned what I know by spending many hours “on line” reading articles and watching tutorials about Adobe Premiere, Adobe After Effects, and Adobe Flash (AS.3) Although I started by learning AS2 I am now trying to make the transition to 3.0 – different thinking, but makes sense. Anyway, R. Blank – how I wish I had your knowledge of Flash/Actionscript 3.0
A big thanks for everything you have contributed to me.
Alyn Murray