Streaming and database connection with red5 media server
This article has been removed from your 'Favourites' list.

Part Two - The client application
Milan Toth
Milan Toth is the Chief Flash Developer of Jasmin Media Group, he created one of the world's biggest flash media server system. He loves Eclipse and OS X, AS3 and JAVA, sci-fi and horror, metal and electronic.
package
{
import flash.net.NetStream;
import flash.net.NetConnection;
import flash.net.ObjectEncoding;
import flash.text.TextField;
import flash.media.Video;
import flash.events.MouseEvent;
import flash.events.NetStatusEvent;
import flash.display.Sprite;
import flash.display.MovieClip;
public class Red5FirstClient extends Sprite
{
private var nc:NetConnection;
private var ns:NetStream;
private var items:Array;
private var video:Video;
public function Red5FirstClient()
{
nc = new NetConnection( );
nc.client = this;
nc.objectEncoding = ObjectEncoding.AMF0;
nc.addEventListener( NetStatusEvent.NET_STATUS , netStatus );
nc.connect( "rtmp://localhost/firstapp" , true );
//we store the buttons representing streams here
items = [ ];
// creating a video instance
video = new Video( );
//place it to the right
video.x = 70;
//attach it to the display list
addChild( video );
}
private function netStatus ( event:NetStatusEvent ):void
{
trace( "netStatus: " + event.info.code );
}
public function message ( message:Object ):void
{
trace( "message " );
//red5first will send stream list here, and we create a button for every stream
for ( var a:* in message )
addItem( message[a] );
}
// creating buttons
public function addItem ( properties:Object ):void
{
trace( "addItem" );
// a button is 20 px height, and we need 2 px row between buttons
var height:Number = items.length * 22;
var newItem:MovieClip = new MovieClip( );
// button label
var newField:TextField = new TextField( );
newField.width = 70;
newField.height = 20;
// setting stream id as button label
newField.text = properties.id;
// storing the other properties in the button
newItem.id = properties.id;
newItem.filename = properties.filename;
newItem.duration = properties.duration;
newItem.y = height + items.length * 2;
// drawing background
newItem.graphics.beginFill( 0x00ff00 , 1 );
newItem.graphics.drawRect( 0 , 0 , 70 , 20 );
newItem.buttonMode = true;
newItem.mouseChildren = false;
// mouseclick event
newItem.addEventListener( MouseEvent.CLICK , playItem );
//attaching label to button
newItem.addChild( newField );
addChild( newItem );
items.push( newItem );
}
public function playItem ( event:MouseEvent ):void
{
trace( "playItem: " + event.target );
// is a stream is already playing, close it
if ( ns != null ) ns.close( );
// new stream
ns = new NetStream( nc );
// onMetaData comes here
ns.client = this;
//starting stream
ns.play( event.target.filename );
//attach stream to video
video.attachNetStream( ns );
}
public function onMetaData ( message:Object ):void
{
trace( "onMetaData: " );
for ( var a:* in message ) trace( a + " : " + message[a] );
}
}
}
Start red5, than run the client, if there are records in the database, buttons will appear in the client, and you can choose and play them, and playing stops after 20 seconds.
After this part creating a startup script is a very good idea, which deletes the previous app from red5/webapps/firstapp/WEB-INF, copies EclipseWorkSpace/Red5FirstApp/WEB-INF under red5/webapps/firstapp, then starts red5.
On OS X, it looks like this:
#!/bin/bash
rm -r /Applications/Red5/webapps/firstapp/WEB-INF
cp -r /Users/milantoth/Store/Development/Workspace/Red5FirstApp/WEB-INF /Applications/Red5/webapps/firstapp
cd /Applications/Red5
./red5.sh
And that's all. Knowing this you can go on with red5 and flash.
Spread The Word
Related Links
5 Responses to "Streaming and database connection with red5 media server" 
|
said this on 05 Jul 2007 10:34:02 AM CST
I have found that Red5 c
|
|
said this on 18 Feb 2009 4:27:20 AM CST
I spent a lot of time to
|
|
said this on 04 Mar 2009 4:25:08 AM CST
Thanks Ivan!!
I figured Thanks a l |
|
said this on 11 Jun 2009 5:31:51 PM CST
It wont work for me... :(
$t.rt app will not load when t Joel |
|
said this on 15 Jul 2009 1:47:36 AM CST
Hey Joel,
I am getting Did yo Thanks. |


Author/Admin)