Marcio Rosa Website

Avatar

Marcio Rosa Interaction Architect.

Combined Record and Playback Application

package
{
  import fl.controls.Button;
  import fl.controls.TextInput;
  import flash.display.MovieClip;
  import flash.net.NetConnection;
  import flash.net.NetStream;
  import flash.events.NetStatusEvent;
  import flash.events.MouseEvent;
  import flash.events.Event;
  //import flash.net.ObjectEncoding;
  import flash.media.Camera;
  import flash.media.Microphone;
  import flash.media.Video;
 
  public class RecordPlay extends MovieClip
  {
        private var nc:NetConnection;
        private var ns:NetStream;
        private var rtmpNow:String;
        private var msg:Boolean;
        private var cam:Camera;
        private var mic:Microphone;
        private var vid1:Video;
        private var vid2:Video;
        private var recordBtn:Button;
        private var stopBtn:Button;
        private var playBtn:Button;
        private var textInput:TextInput;
        private var metaSniffer:Object;
        private var dur:Number;
 
        function RecordPlay ()
        {
             //NetConnection.defaultObjectEncoding = flash.net.ObjectEncoding.AMF0;
             nc=new NetConnection();
             nc.addEventListener (NetStatusEvent.NET_STATUS,checkConnect);
             rtmpNow="rtmp://192.168.0.11/vid2/recordings";
             //rtmpNow="rtmp:/vid2/recordings";
             nc.connect (rtmpNow);
             addMedia ();
             addUI ();
             recordBtn.addEventListener (MouseEvent.CLICK,startRecord);
             stopBtn.addEventListener (MouseEvent.CLICK,stopAll);
             playBtn.addEventListener (MouseEvent.CLICK,startPlay);
        }
 
        private function checkConnect (e:NetStatusEvent):void
        {
             msg=(e.info.code=="NetConnection.Connect.Success");
             if (msg)
             {
                   ns = new NetStream(nc);
                   metaSniffer=new Object();
                   ns.client=metaSniffer;
                   metaSniffer.onMetaData=getMeta;
             }
        }
 
        private function getMeta (mdata:Object):void
        {
             //Dummy to avoid error
        }
 
        private function addMedia ():void
        {
             cam=Camera.getCamera();
             cam.setKeyFrameInterval (12);
             cam.setMode (240,180,15);
             cam.setQuality (0,80);
             mic=Microphone.getMicrophone();
             mic.rate=11;
             videoSetup ();
        }
 
        private function videoSetup ():void
        {
             vid1=new Video(cam.width,cam.height);
             vid1.attachCamera (cam);
             vid1.x=100;
             vid1.y=70;
             addChild (vid1);
             vid2=new Video(cam.width,cam.height);
             vid2.x=vid1.x+vid1.width+10;
             vid2.y=vid1.y;
             addChild (vid2);
        }
 
        private function addUI ():void
        {
             recordBtn=new Button();
             recordBtn.label="Record";
             recordBtn.x=100;
             recordBtn.y=70+(cam.height) +5;
             recordBtn.width=70;
             addChild (recordBtn);
             stopBtn=new Button();
             stopBtn.label="Stop";
             stopBtn.x=recordBtn.x+100;
             stopBtn.y=recordBtn.y;
             stopBtn.width=60;
             addChild (stopBtn);
             playBtn=new Button();
             playBtn.label="Play";
             playBtn.x=stopBtn.x+85;
             playBtn.y=recordBtn.y;
             playBtn.width=60;
             addChild (playBtn);
             textInput=new TextInput();
             textInput.x=recordBtn.x;
             textInput.y=recordBtn.y + 30;
             addChild (textInput);
        }
 
        private function startRecord (e:Event):void
        {
             if (ns)
             {
                   recordBtn.label="Recording";
                   ns.attachAudio (mic);
                   ns.attachCamera (cam);
                   ns.publish (textInput.text,"record");
             }
        }
 
        private function stopAll (e:Event):void
        {
             playBtn.label="Play";
             recordBtn.label="Record";
             ns.close ();
        }
 
        private function startPlay (e:Event):void
        {
             if (ns)
             {
                   playBtn.label="Playing";
                   vid2.attachNetStream (ns);
                   ns.play (textInput.text);
             }
        }
  }
}

Minimum Code to Play FLV File

package
{
  import fl.controls.Button;
  import fl.controls.TextInput;
  import flash.display.Sprite;
  import flash.net.NetConnection;
  import flash.net.NetStream;
  import flash.events.NetStatusEvent;
  import flash.events.MouseEvent;
  import flash.events.Event;
  //import flash.net.ObjectEncoding;
  import flash.media.Video;
 
  public class MinPlay extends Sprite
  {
        private var nc:NetConnection;
        private var ns:NetStream;
        private var rtmpNow:String;
        private var msg:Boolean;
        private var vid1:Video;
        private var playBtn:Button;
        private var stopBtn:Button;
        private var textInput:TextInput;
        private var metaSniffer:Object;
        private var dur:Number;
 
        function MinPlay ()
        {
             //NetConnection.defaultObjectEncoding = flash.net.ObjectEncoding.AMF0;
             nc=new NetConnection();
             nc.addEventListener (NetStatusEvent.NET_STATUS,checkConnect);
             rtmpNow="rtmp://192.168.0.11/vid2/recordings";
             //rtmpNow="rtmp:/vid2/recordings";
             nc.connect (rtmpNow);
             addMedia ();
             addUI ();
             playBtn.addEventListener (MouseEvent.CLICK,startPlay);
             stopBtn.addEventListener (MouseEvent.CLICK,stopPlay);
        }
 
        private function addMedia ():void
        {
             vid1=new Video(240,180);
             addChild (vid1);
             vid1.x=100;
             vid1.y=50;
        }
 
        private function addUI ():void
        {
             playBtn=new Button();
             playBtn.label="Play";
             playBtn.x=100;
             playBtn.y=180 +55;
             playBtn.width=60;
             addChild (playBtn);
             stopBtn=new Button();
             stopBtn.label="Stop Playing";
             stopBtn.width=80;
             stopBtn.x=playBtn.x+180;
             stopBtn.y=playBtn.y;
             addChild (stopBtn);
             textInput=new TextInput();
             textInput.x=playBtn.x;
             textInput.y=playBtn.y + 30;
             addChild (textInput);
        }
 
        private function checkConnect (e:NetStatusEvent):void
        {
             msg=(e.info.code=="NetConnection.Connect.Success");
             if (msg)
             {
                   ns = new NetStream(nc);
                   metaSniffer=new Object();
                   ns.client=metaSniffer;
                   metaSniffer.onMetaData=getMeta;
             }
        }
 
        private function getMeta (mdata:Object):void
        {
             for (var prop:Object in mdata)
             {
                   trace (prop+" = "+mdata[prop]);
             }
        }
 
        private function startPlay (e:Event):void
        {
             if (ns)
             {
                   playBtn.label="Playing";
                   vid1.attachNetStream (ns);
                   ns.play (textInput.text);
             }
        }
 
        private function stopPlay (e:Event):void
        {
             playBtn.label="Play";
             ns.play (false);
             ns.close ();
        }
  }
}

Minimum Code to Record FLV File

package
{
    import fl.controls.Button;
    import fl.controls.TextInput;
    import flash.display.Sprite;
    import flash.net.NetConnection;
    import flash.net.NetStream;
    import flash.events.NetStatusEvent;
    import flash.events.MouseEvent;
    import flash.events.Event;
    //import flash.net.ObjectEncoding;
    import flash.media.Camera;
    import flash.media.Microphone;
    import flash.media.Video;
 
    public class MinRecord extends Sprite
    {
          private var nc:NetConnection;
          private var ns:NetStream;
          private var rtmpNow:String;
          private var msg:Boolean;
          private var cam:Camera;
          private var mic:Microphone;
          private var vid1:Video;
          private var recordBtn:Button;
          private var stopBtn:Button;
          private var textInput:TextInput;
 
          //Constructor
          function MinRecord ()
          {
               //NetConnection.defaultObjectEncoding = flash.net.ObjectEncoding.AMF0;
               nc=new NetConnection();
               nc.addEventListener (NetStatusEvent.NET_STATUS,checkConnect);
               rtmpNow="rtmp://192.168.0.11/vid2/recordings";
               //rtmpNow="rtmp:/vid2";
               nc.connect (rtmpNow);
               addMedia ();
               addUI ();
               recordBtn.addEventListener (MouseEvent.CLICK,startRecord);
               stopBtn.addEventListener (MouseEvent.CLICK,stopRecord);
          }
 
          private function addMedia ():void
          {
               cam=Camera.getCamera();
               cam.setMode (240,180,24);
               cam.setQuality (0,90);
               mic=Microphone.getMicrophone();
               vid1=new Video(cam.width,cam.height);
               vid1.attachCamera (cam);
               addChild (vid1);
               vid1.x=100;
               vid1.y=50;
          }
 
          private function addUI ():void
          {
               recordBtn=new Button();
               recordBtn.label="Record";
               recordBtn.x=100;
               recordBtn.y=50+(cam.height) +5;
               recordBtn.width=70;
               addChild (recordBtn);
               stopBtn=new Button();
               stopBtn.label="Stop Record";
               stopBtn.x=recordBtn.x+85;
               stopBtn.y=recordBtn.y;
               stopBtn.width=75;
               addChild (stopBtn);
               textInput=new TextInput();
               textInput.x=recordBtn.x;
               textInput.y=recordBtn.y + 30;
               addChild (textInput);
          }
 
          private function checkConnect (e:NetStatusEvent):void
          {
               msg=(e.info.code=="NetConnection.Connect.Success");
               if (msg)
               {
                     ns = new NetStream(nc);
               }
          }
 
          private function startRecord (e:Event):void
          {
               if (ns)
               {
                     recordBtn.label="Recording";
                     ns.attachAudio (mic);
                     ns.attachCamera (cam);
                     ns.publish (textInput.text,"record");
               }
          }
 
          private function stopRecord (e:Event):void
          {
               recordBtn.label="Record";
               ns.close ();
          }
    }
}

Recording and Playing Back Streaming Audio and Video | Streaming and Broadcasting

Flash Media Server 3 can both record and play back streaming audio and video. The nature of streaming is not the same as broadcasting. In broadcasting, the sender sends out a single signal; everyone who connects to the channel sending the signal gets the same stream. It’s like dropping a pebble in the water—a concentric circle of waves sends out a “signal.” No matter where viewers or listeners are, when the wave reaches them, they get the same wave—like a TV picture or radio transmission—as everyone else.

When FMS3 sends out a stream of audio and video, it creates a separate stream for each recipient. Its “broadcasting” works more like the spokes on a wagon wheel, where everyone connected gets his or her own stream. So here the term “broadcasting,” really means a form of streamcasting—a technology where everyone gets a separate stream. If one person is listening, my application sends only a single stream; but if 20 people are listening, it generates 20 streams. Because the server automatically creates a separate stream for each user connected, you don’t have to create all those streams in your coding. However, in deciding how to set up your application, for bandwidth considerations you need to consider the number of streams it may generate.

If you’ve ever viewed online video, you’ve probably seen different kinds without really realizing it. If you click on a video and have to wait a long time, what you’re really waiting for is for the video file to first download and then for your computer to play the video that’s saved to your hard drive. That works fine except you have to wait until the file is fully downloaded before you can watch it. Also, it’s saved on your hard drive taking up space. A second type of video processing is called progressive download. It’s like a hybrid of a video download and streaming. As the video file is downloaded, it begins to play rather than wait for the whole thing to download. However, the file will end up on the user’s hard drive, and processing is not as smooth as true streaming. The third type of video processing, if you have FMS3 on your server, lets you stream video files from the server. This chapter explains how to get started with both creating and streaming Flash Video (FLV) files using FMS3.

Streaming and Broadcasting

Flash Media Server 3 can both record and play back streaming audio and video. The nature of streaming is not the same as broadcasting. In broadcasting, the sender sends out a single signal; everyone who connects to the channel sending the signal gets the same stream. It’s like dropping a pebble in the water—a concentric circle of waves sends out a “signal.” No matter where viewers or listeners are, when the wave reaches them, they get the same wave—like a TV picture or radio transmission—as everyone else.

When FMS3 sends out a stream of audio and video, it creates a separate stream for each recipient. Its “broadcasting” works more like the spokes on a wagon wheel, where everyone connected gets his or her own stream. So here the term “broadcasting,” really means a form of streamcasting—a technology where everyone gets a separate stream. If one person is listening, my application sends only a single stream; but if 20 people are listening, it generates 20 streams. Because the server automatically creates a separate stream for each user connected, you don’t have to create all those streams in your coding. However, in deciding how to set up your application, for bandwidth considerations you need to consider the number of streams it may generate.

If you’ve ever viewed online video, you’ve probably seen different kinds without really realizing it. If you click on a video and have to wait a long time, what you’re really waiting for is for the video file to first download and then for your computer to play the video that’s saved to your hard drive. That works fine except you have to wait until the file is fully downloaded before you can watch it. Also, it’s saved on your hard drive taking up space. A second type of video processing is called progressive download. It’s like a hybrid of a video download and streaming. As the video file is downloaded, it begins to play rather than wait for the whole thing to download. However, the file will end up on the user’s hard drive, and processing is not as smooth as true streaming. The third type of video processing, if you have FMS3 on your server, lets you stream video files from the server. This chapter explains how to get started with both creating and streaming Flash Video (FLV) files using FMS3.

Meu primeiro grande projeto com FMS

Portfolio FMS Marcio Rosa

JSON e Flash (ActionScript 2.0)

O que e JSON?
JSON (JavaScript Object Notation) é um formato leve para intercâmbio de dados baseado em um subconjunto do JavaScript (linguagem de programação baseada em ECMA Standard), mesmo padrão do ActionScript( ECMA 262). JSON é um formato de texto que é completamente independente de sua linguagem, apesar de utilizar convenções que familiares de programadores da família de C, incluindo C, C + +, C #, Java, Javascript, Perl, Python, e muitas outras.

ActionScript Resources:

Exemplo usando classe JSON.as (ActionScript 2.0)

import JSON;
var jsondata:LoadVars = new LoadVars();
jsondata.onLoad = function() {
var jsonObj = JSON.stringify(jsondata);
trace(jsonObj)
};

jsondata.load(”http://del.icio.us/feeds/json/marciorosa”);

Exemplo usando JSONConnector:


Download Fla Source

AdobeTV e Adobe Media Player

A Adobe lança hoje um novo site chamado AdobeTV (tv.adobe.com). O site hospeda muitos vídeos para profissionais de core bussiness Adobe e funciona perfeitamente com o Adobe Media Player, que aliás também lança hoje.

Dentro do mercado acompanho uma grande onda de projetos  para vídeos e Flash Media Server.
Logo estarei disponibilizando esta categoria no blog.

,

Before you go

Going so soon? May these links be a guide to web project.