Skip to main content
Inspiring
October 26, 2010
Answered

video record

  • October 26, 2010
  • 1 reply
  • 3805 views

Hi,

Am trying to record video from my webcam.

here is my code

var nc:NetConnection;
var ns:NetStream;
var nsPlayer:NetStream;
var vid:Video;
var vidPlayer:Video;
var cam:Camera;
var mic:Microphone;

nc = new NetConnection();
nc.addEventListener(NetStatusEvent.NET_STATUS,onNetStatus);
nc.connect("rtmp://localhost/publishlive");

function onNetStatus(event:NetStatusEvent):void{
    trace(event.info.code);
    if(event.info.code == "NetConnection.Connect.Success"){

   }

function publishCamera(e:Event) {
    cam = Camera.getCamera();
    mic = Microphone.getMicrophone();
    ns = new NetStream(nc);
    ns.attachCamera(cam);
    ns.attachAudio(mic);
    ns.publish("myCamera", "live");
    displayPublishingVideo();
}

function displayPublishingVideo() {
    vid = new Video();
    vid.x = 10;
    vid.y = 10;
    vid.attachCamera(cam);
    addChild(vid); 
}


function displayPlaybackVideo(e:Event){
    nsPlayer = new NetStream(nc);
    nsPlayer.play("myCamera");
    vidPlayer = new Video();
    vidPlayer.x = cam.width + 20;
    vidPlayer.y = 10;
    vidPlayer.attachNetStream(nsPlayer);
    addChild(vidPlayer);
}

record_btn.addEventListener(MouseEvent.CLICK , publishCamera)
play_btn.addEventListener(MouseEvent.CLICK , displayPlaybackVideo)

When i click record_btn, flash asks me permission to access my webcam.

If i alow in the screen i am able to see live video.

But I want to store the video and replay it.

Please help to complete this.

Thanks,

Shanthi

    This topic has been closed for replies.
    Correct answer SE_0208

    I have already replied to your other query - so that has answer for this one. Let me know if that does not work out. try and let me know if it worked or not.

    1 reply

    SE_0208Correct answer
    Participating Frequently
    October 26, 2010

    I have already replied to your other query - so that has answer for this one. Let me know if that does not work out. try and let me know if it worked or not.

    Participating Frequently
    October 26, 2010

    Can you paste your entire code?

    Inspiring
    October 26, 2010

    import flash.events.Event;

    var nc:NetConnection;
    var ns:NetStream;
    var nsPlayer:NetStream;
    var vid:Video;
    var vidPlayer:Video;
    var cam:Camera;
    var mic:Microphone;
    nc = new NetConnection();
    nc.addEventListener(NetStatusEvent.NET_STATUS,onNetStatus);
    nc.connect("rtmp://localhost/publishlive");

    function onNetStatus(event:NetStatusEvent):void{
        trace(event.info.code);
        if(event.info.code == "NetConnection.Connect.Success"){

       }

    function publishCamera(e:Event) {
        cam = Camera.getCamera();
        mic = Microphone.getMicrophone();
        ns = new NetStream(nc);
        ns.attachCamera(cam);
        ns.attachAudio(mic);
        ns.publish("myCameraa","record")
        displayPublishingVideo();
    }

    function displayPublishingVideo() {
        vid = new Video();
        vid.x = 10;
        vid.y = 10;
        vid.attachCamera(cam);
        addChild(vid); 
    }


    function displayPlaybackVideo(e:Event){
        nsPlayer = new NetStream(nc);
        nsPlayer.play("myCameraa",0,-1);
        vidPlayer = new Video();
        vidPlayer.x = cam.width + 20;
        vidPlayer.y = 10;
        vidPlayer.attachNetStream(nsPlayer);
        addChild(vidPlayer);
    }

    function stopCamera(e:Event)
    {
        ns.publish(false);
    }
    stop_btn.addEventListener(MouseEvent.CLICK , stopCamera);
    record_btn.addEventListener(MouseEvent.CLICK , publishCamera);
    play_btn.addEventListener(MouseEvent.CLICK , displayPlaybackVideo);

    When i click on the record_btn i get error message like this

    NetConnection.Connect.Success
    Error #2044: Unhandled NetStatusEvent:. level=error, code=NetStream.Record.NoAccess
        at videorecord_fla::MainTimeline/publishCamera()
    NetConnection.Connect.Closed

    Thanks,

    Shanthi