Cast for two

Friday, August 31, 2007

Embedding MP4 in HTML with Flash 9 beta Moviestar

From Jeroen Wijering I found a way to play MP4 movies in a webpage using the new Flash Version 9 beta, nicknamed Moviestar. It uses SWFObject to embed a Flash file using Javascript and the mediaplayer by Jeroen.
This is the code:


<script type="text/javascript" src="swfobject.js"></script>


<p id="player1">

<a href="http://www.macromedia.com/go/getflashplayer">

Get the Flash Player</a> to see this player.

</p>


<script type="text/javascript">

var s1 = new SWFObject("mediaplayer.swf","single","384","224","7");

s1.addParam("allowfullscreen","true");

s1.addVariable("file","test.mp4");

s1.addVariable("image","preview.jpg");

s1.addVariable("overstretch","none");

s1.addVariable("smoothing","false");

s1.write("player1");

</script>

In the same directory above code is residing, store swfobject.js,test.mp4,preview.jpg and mediaplayer.swf.
The result looks like this:

I don't understand yet when clicking on fullscreen, the video does not resize but that's probably an option of mediaplayer I have to enable. Also, I have the impression the movie is first downloaded before playback starts. I am quite sure the header atoms in test.mp4 are in front of the file. So the movie should faststart. Here is an example where it does work. Any suggestions welcome in the comment.

UPDATE:
leaving out the overstrech variable so that is get the default true value, stretches the movie to fullscreen in fullscreen mode. No problem now with the fast start. So the code becomes:

<script type="text/javascript" src="swfobject.js"></script>


<p id="player1">

<a href="http://www.macromedia.com/go/getflashplayer">

Get the Flash Player</a> to see this player.

</p>


<script type="text/javascript">

var s1 = new SWFObject("mediaplayer.swf","single","384","224","7");

s1.addParam("allowfullscreen","true");

s1.addVariable("file","test.mp4");

s1.addVariable("image","preview.jpg");

s1.write("player1");

</script>

4 comments:

marc said...

hi,

Thanks for posting this!

Shouldn't the flash version required be 9 not 7?

Or does the mediaplayer decode h.264/ACC on its own using only Flash 7?

I thought Adobe only introduced h.264/aac support in Flash 9?

cast42 said...

@marc MPEG-4 AVC/AAC decoding is only possible from Flash 9 Update 3 (See here http://www.adobe.com/aboutadobe/pressroom/pressreleases/200712/120407adobemoviestar.html )

Aaron said...

Marc's point was that the code you posted tells Flash Player that the minimum requirement for this SWF is Flash 7. It should probably be 9.0.115, like so:


var s1 = new SWFObject("mediaplayer.swf","single","384","224","9.0.115");

Diyalabs said...

Thanks for sharing such a helpful, and understandable blog. I really enjoyed reading it.

Robots for kids
Robotic Online Classes
Robotics School Projects
Programming Courses Malaysia
Coding courses
Coding Academy
coding robots for kids
Coding classes for kids
Coding For Kids