Recording Streaming with Flash Communication Server/Flash Media Server.

Some times are frustrating using to have it that to lower the archive all it stops later attending its content being about connections still more dialed. E as natural evolution of this situation, the content saw streaming. After all, a series of services, as notice and transmissions to the living creature, radios online, would not be viaveis without this technology.

Streaming is basically a technology that the user allows to have access to the content multimedia without the obligation to download the archive. It functions of the following form: When the clica user in one link requesting the reproduction of an archive streaming, initiates download of the information. Before starting to execute streaming, player he stores a certain volume of data in a buffer, so that the transmission occurs without interruptions. When the buffer is filled, player reproduces the content.

To record streaming using the FlashCom/Flash Media Server is sufficiently easy. will not need to still write codigo in asc (ActionScript Communication File), so will use action script of the side of the customer. It opens a new document in the Flash, we go to create two movies clips of the video type, to add to a video object in its library, opens the panel library (windomVideo object you your library, open the Library panel (Window > Library or Ctrl+L or F11) adds to one embedded Video object to it selecting New Video in the options of library.

We will create one button for when clicking, Flash orders the writing for the Flash Communication Server/Flash Media Server and another button to stop the writing. A Play button will serve to show the recorded video.

We will use the ActionScript to capture camera and to attach to the video object, to create a connection with the server, to record the data of camera and to order as streaming to the server and to touch the writing in as video object. When you record one streaming in the Flash, the server creates archives with the extensions .flv for video and .idx for audio.

Embedded Video drags two objects of library for palco and the names of instance of Live_video and Replay_video. The buttons that will chain the dinâmicamentes actions will be servant, certify that buttons are in library of the film. In the first frame of timeline, it opens the Actions panel (F9).

[as]
var Play_btn = _root.createClassObject(mx.controls.Button,”Play_btn”,_root.getNextHighestDepth(),{_x:120,_y:375,label:”Play”});
var Record_btn = _root.createClassObject(mx.controls.Button,”Record_btn”,_root.getNextHighestDepth(),{_x:15,_y:375,label:”Record”});
[/as]

To define its application in the server, it creates a called diretorio “gravando_stream” in its server of the Flash Communication Server/Flash Media Server. We go to call the metodos that bind camera and the microphone

[as]
client_cam = Camera.get();
client_mic = Microphone.get();
Live_video.attachVideo(client_cam);
[/as]

Now we will create a function to connect to the serving Flash Communication Server/Flash Measured Server, beyond ordering the video to the server and to catch the video saw streaming again

[as]
function initStreams() {
client_nc = new NetConnection();
/*quando for usar um servidor que não seja localhost use rtmp://*/
client_nc.connect(“rtmp:/gravando_stream”);
client_nc.onStatus = function(info) {
trace(“Level: ” + info.level + ” Code: ” + info.code);
}
out_ns = new NetStream(client_nc);
in_ns = new NetStream(client_nc);
Replay_video.attachVideo(in_ns);
}
initStreams();
[/as]

Another function will be created to record the video in the server. It notices that publish is added parametro “record” to metodo, this say to the serving Flash Communication Server/Flash Media Server that is for recording stream it in the server.

[as]
function doRecord(){
if (Record_btn.label == “Record”){
out_ns.attachVideo(client_cam);
out_ns.attachAudio(client_mic);
out_ns.publish(“my_recorded_stream”, “record”);
Play_btn.enabled = false;
Record_btn.label = “Stop”;
} else if (Record_btn.label == “Stop”){
out_ns.close();
Play_btn.enabled = true;
Record_btn.label = “Record”;
}
}

[/as]

Function for botao Play, will touch the video recorded saw stream

[as]
function doPlay() {
in_ns.play(“my_recorded_stream”);
}
[/as]

It gives to ctrl+enter to test the application Click in the Record button to start to record stream it later Stop, click in the Play button to see the video. Apos the writing, in its server must be to form something similar to this image, created the folder stream and inside of it the folder inside gravando_stream and of this our archives .flv and .idx.

[img]http://www.leonardofranca.com.br/wp-content/gravando_stream.jpg[/img]

It follows code complete:
[as]
client_cam = Camera.get();
client_mic = Microphone.get();
Live_video.attachVideo(client_cam);
function initStreams() {
client_nc = new NetConnection();
client_nc.connect(“rtmp:/gravando_stream”);
client_nc.onStatus = function(info) {
trace(“Level: “+info.level+” Code: “+info.code);
};
out_ns = new NetStream(client_nc);
in_ns = new NetStream(client_nc);
Replay_video.attachVideo(in_ns);
}
initStreams();
function doRecord() {
if (Record_btn.label == “Record”) {
out_ns.attachVideo(client_cam);
out_ns.attachAudio(client_mic);
out_ns.publish(“my_recorded_stream”, “record”);
Play_btn.enabled = false;
Record_btn.label = “Stop”;
} else if (Record_btn.label == “Stop”) {
out_ns.close();
Play_btn.enabled = true;
Record_btn.label = “Record”;
}
}
function doPlay() {
in_ns.play(“my_recorded_stream”);
}
Play_btn = _root.createClassObject(mx.controls.Button, “Play_btn”, _root.getNextHighestDepth(), {_x:120, _y:375, label:”Play”});
var Record_btn = _root.createClassObject(mx.controls.Button, “Record_btn”, _root.getNextHighestDepth(), {_x:15, _y:375, label:”Record”});
Record_btn.onRelease = function():Void {
doRecord();
};
Play_btn.onRelease = function():Void {
doPlay();
};

[/as]

see the app working

more
Flash Media Server Developer Center
http://www.macromedia.com/devnet/flashmediaserver/

FlashComGuru
http://www.flashcomguru.com/

FlashCom.com.br
http://www.flashcom.com.br/

Flash Media Server Fun
http://www.fczone.com/

Was this article helpful? feel free to make a donation and help keep the blog in the air

Leave a Reply