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).


  1. var Play_btn = _root.createClassObject(mx.controls.Button,"Play_btn",_root.getNextHighestDepth(),{_x:120,_y:375,label:"Play"});
  2. var Record_btn = _root.createClassObject(mx.controls.Button,"Record_btn",_root.getNextHighestDepth(),{_x:15,_y:375,label:"Record"});

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


  1. client_cam = Camera.get();
  2. client_mic = Microphone.get();
  3. Live_video.attachVideo(client_cam);

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


  1. function initStreams() {
  2.     client_nc = new NetConnection();
  3.         /*quando for usar um servidor que não seja localhost use rtmp://*/
  4.         client_nc.connect("rtmp:/gravando_stream");
  5.         client_nc.onStatus = function(info) {
  6.             trace("Level: " + info.level + " Code: " + info.code);
  7.         }
  8.         out_ns = new NetStream(client_nc);
  9.         in_ns = new NetStream(client_nc);
  10.         Replay_video.attachVideo(in_ns);
  11. }
  12. initStreams();

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.


  1. function doRecord(){
  2.     if (Record_btn.label == "Record"){
  3.             out_ns.attachVideo(client_cam);
  4.                 out_ns.attachAudio(client_mic);
  5.                 out_ns.publish("my_recorded_stream", "record");
  6.                 Play_btn.enabled = false;
  7.                 Record_btn.label = "Stop";
  8.         } else if (Record_btn.label == "Stop"){
  9.             out_ns.close();
  10.                 Play_btn.enabled = true;
  11.             Record_btn.label = "Record";
  12.         }
  13. }

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


  1. function doPlay() {
  3. }

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.


It follows code complete:


  1. client_cam = Camera.get();
  2. client_mic = Microphone.get();
  3. Live_video.attachVideo(client_cam);
  4. function initStreams() {
  5.     client_nc = new NetConnection();
  6.         client_nc.connect("rtmp:/gravando_stream");
  7.         client_nc.onStatus = function(info) {
  8.             trace("Level: "+info.level+" Code: "+info.code);
  9.         };
  10.         out_ns = new NetStream(client_nc);
  11.         in_ns = new NetStream(client_nc);
  12.         Replay_video.attachVideo(in_ns);
  13. }
  14. initStreams();
  15. function doRecord() {
  16.     if (Record_btn.label == "Record") {
  17.             out_ns.attachVideo(client_cam);
  18.             out_ns.attachAudio(client_mic);
  19.             out_ns.publish("my_recorded_stream", "record");
  20.             Play_btn.enabled = false;
  21.             Record_btn.label = "Stop";
  22.         } else if (Record_btn.label == "Stop") {
  23.             out_ns.close();
  24.             Play_btn.enabled = true;
  25.             Record_btn.label = "Record";
  26.         }
  27. }
  28. function doPlay() {
  30. }
  31. Play_btn = _root.createClassObject(mx.controls.Button, "Play_btn", _root.getNextHighestDepth(), {_x:120, _y:375, label:"Play"});
  32. var Record_btn = _root.createClassObject(mx.controls.Button, "Record_btn", _root.getNextHighestDepth(), {_x:15, _y:375, label:"Record"});
  33. Record_btn.onRelease = function():Void {
  34.     doRecord();
  35. };
  36. Play_btn.onRelease = function():Void {
  37.     doPlay();
  38. };

see the app working

Flash Media Server Developer Center


Flash Media Server Fun

Flash Media Server, Principal

Leave a Reply