How to Create a Streaming Flash Video Player Using Ming PHP or Ruby

I mentioned in creating Flash videos using FFMpeg that you could use Ming to create your own Flash video player. I’ve added a patch to the ruby -ming extension for video streaming so now it is possible to create a streaming player with both PHP and Ruby using their Ming extensions. The following examples show you how.

First a little background. You can read about playing back external FLV files dynamically with actionscript at the Macromedia website. It includes references to the NetConnect class and NetStream class that together let you stream a FLV file. The main thing Ming does for you in the following simple examples is give you a SWF with a video player in it and let you attach some action script to it.

Here is how you do it in PHP:

[code lang=”php”]
setDimension(320,240);
$movie->setBackground(0x33,0x33,0x33);
$movie->setRate(8);

$strAction = ”
stop();
netConn=new NetConnection();
netConn.connect(null);
vStream=new NetStream(netConn);
video1.attachVideo(vStream);
vStream.setBufferTime(10);
vStream.play(‘http://localhost/test.flv’);
“;

$stream = new SWFVideoStream();
$item=$movie->add($stream);
$item->setname(“video1”);
$movie->add(new SWFAction($strAction));
$movie->nextFrame();

$movie->save(“videostream.swf”);
?>
[/code]

And here is how you do it with Ruby:

[code lang=”ruby”]
#!/usr/bin/env ruby

require ‘ming/ming’
include Ming

Ming::set_scale(10.0000000)

movie = SWFMovie.new(7)
movie.set_background(0xff, 0xff, 0xff)
movie.set_dimension(320, 240)
movie.set_rate(8)

strAction = ‘
stop();
netConn=new NetConnection();
netConn.connect(null);
vStream=new NetStream(netConn);
video1.attachVideo(vStream);
vStream.setBufferTime(10);
vStream.play(\’http://localhost/test.flv\’);

vstream = SWFVideoStream.new
item = movie.add(vstream)

item.set_name(“video1”)
movie.add(SWFAction.new(strAction))
movie.next_frame()

movie.save(“videostream.swf”)
[/code]

Here is the result of the above examples:

[tags]flash, php, ruby, flv[/tags]

4 thoughts on “How to Create a Streaming Flash Video Player Using Ming PHP or Ruby

  1. Pingback: Using Flash video metadata to display annotations @ IONCANNON

  2. Arifur Rahman

    Hi,

    Do I need to add any library to execute above code? If so, where can I find that?

    Thanks
    Arif

  3. Ali Hassaan

    Hi,
    I am searching for the right code to create a custom video streaming player for flash files. I am not sure if this is the right one. But can you guide me with this ?

    thank you,

Comments are closed.