Search code examples
actionscript-3red5

Red5 and AS3 - file "Mystream" is deleted (not recording)


This my first time using StackExchange so I apologize if I miss anything.

I am trying to create a AS3 Flash that will record a video using a webcam and RED5 media server; I am stuck (I am not a programmer, more of a computer handyman that does everything). The example that comes with RED5 works fine (though is in AS2 and I could not, for some reason, make certain things I need to do work), but my code doesnt seem to record the stream as there is not file, the RED5 console only says:

[INFO] [NioProcessor-3] org.red5.server.adapter.ApplicationAdapter - File lecture.flv was deleted

here is the code so far. (updated 09/07/12)

import flash.display.Sprite;
import flash.net.NetConnection;
import flash.net.NetStream;
import flash.media.Camera;
import flash.events.MouseEvent;
import flash.media.Microphone;
import flash.events.*;
import flash.media.Video;

var _cam:Camera
var _mic:Microphone

// create basic netConnection object
var _nc:NetConnection = new NetConnection();

_nc.client = this
// connect to the local Red5 server
_nc.connect("rtmp://localhost/myapp");
_nc.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);

//Add listeners for buttons
record_btn.addEventListener( MouseEvent.CLICK, recordvid );
stop_btn.addEventListener( MouseEvent.CLICK, stopvideo );
//submit_btn.addEventListener( MouseEvent.CLICK, onSubmit );
//Listeners

function netStatusHandler(event:NetStatusEvent):void{
trace("start netstatus handler");
if (event.info.code == "NetConnection.Connect.Success"){
   attachCamera();
                                                      }
}

function attachCamera(e:Event = null):void {
    trace("attach");
        //Attach Camera to field
        _cam=Camera.getCamera();
        _mic=Microphone.getMicrophone()
        vid.attachCamera(_cam);

}

function stopvideo(e:MouseEvent):void {
    //_ns.close();
}

function recordvid(e:MouseEvent):void {
    var _ns:NetStream = new NetStream(_nc);
     trace("publish");
     _ns.attachCamera(_cam);
     _ns.attachAudio(_mic);
     _ns.publish("lecture", "record");
}

Solution

  • I just found the answer thru extreme googleing, I needed to declare the Netstream variable outside the function; otherwise the "publish" video was "empty" as the garbage collector was destroying my variable at some point.

    so outside a function I declare

    var _ns:NetStream;
    

    and inside the function I declare:

    function recordvid(e:MouseEvent):void {
         _ns = new NetStream(_nc);
         _ns.attachCamera(_cam);
         _ns.attachAudio(_mic);
         _ns.publish("lecture", "record");
    

    Awesomely enough, I found the answer right here in stackoverflow