Skip to main content
Participant
April 15, 2009
Question

Broadcasting stops itself in the bigger .fla?? :S

  • April 15, 2009
  • 3 replies
  • 703 views

Hi!

I want to broadcast my webcam.

I have 2 fla's one is nearly empty and the other one is very big.

the bigger one has many movieclips other .as classes but it doesn't run them,

the code running in both fla's are exacty same!

I watch these webcams from another receiver flash.

When i use the bigger one stops broadcasting after a few seconds,

but the smaller fla's broadcast is received all the time???

What should i do to fix the bigger fla??

The broadcastion code is simple

Header 1
package {
    import flash.display.Sprite;
    import flash.events.*;
    import flash.media.*;
    import flash.net.*;
    import flash.text.TextField;
    import flash.text.TextFieldAutoSize;
    import flash.utils.Timer;
    import flash.events.TimerEvent;
    import flash.events.StatusEvent;
    import flash.events.MouseEvent;
    import flash.system.SecurityPanel;
    import flash.system.Security;

    public class streamer extends Sprite
    {
        var vid:Video;
        private var cam:Camera;
        private var t:Timer = new Timer(1000);
        private var my_nc:NetConnection = new NetConnection();
       
        public function streamer()
        {
            this.stage.addEventListener(Event.ENTER_FRAME, myEnterFrame);
           
            cam = Camera.getCamera();
           
            if(!cam)
            {
                myTextField.text = "No camera is installed.";   
            }
            else if (cam.muted)
            {
                myTextField.text = "To enable the use of the camera,\n"
                                 + "please click on this text field.\n"
                                 + "Grant access to your camera.";

                myTextField.addEventListener(MouseEvent.CLICK, clickHandler);

            }else
            {
                myTextField.text = "Connecting";
                connectCamera();
               
                goLive();
            }
  
            addChild(myTextField);

            t.addEventListener(TimerEvent.TIMER, timerHandler);
        }

        function myEnterFrame(evt:Event)
        {
            this.setChildIndex(myTextField, this.numChildren - 1);
            this.setChildIndex(vid, this.numChildren - 1);
        }
       
        private function clickHandler(e:MouseEvent):void
        {
            Security.showSettings(SecurityPanel.PRIVACY);

            cam.addEventListener(StatusEvent.STATUS, statusHandler);

            myTextField.removeEventListener(MouseEvent.CLICK, clickHandler);
        }

        private function statusHandler(event:StatusEvent):void {

            if (event.code == "Camera.Unmuted") {
                connectCamera();
                cam.removeEventListener(StatusEvent.STATUS, statusHandler);
            }
        }

        private function connectCamera():void
        {
            vid = new Video(cam.width, cam.height);
            vid.x = 0;
            vid.y = 0;
            vid.attachCamera(cam);
            addChild(vid);
           
            t.start();
        }

        private function timerHandler(event:TimerEvent):void
        {
            myTextField.text = "fps: " + Math.round(cam.currentFPS);
            /*
            myTextField.appendText("bandwidth: " + cam.bandwidth + "\n");
            myTextField.appendText("currentFPS: " + Math.round(cam.currentFPS) + "\n");
            myTextField.appendText("fps: " + cam.fps + "\n");
            myTextField.appendText("keyFrameInterval: " + cam.keyFrameInterval + "\n");
            */
        }
       
        private function goLive()
        {
            my_nc = new NetConnection();
            my_nc.client = this;
            my_nc.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
            my_nc.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler);
            my_nc.connect("rtmp://localhost/live/livestream");
        }
       
        private function startLive()
        {
            // capture my camera and publish "my_cam" to server
            var publisher:NetStream = new NetStream(my_nc);
           
            publisher.attachAudio(Microphone.getMicrophone());
            publisher.attachCamera(Camera.getCamera());
            publisher.publish("livestream", "live");
           
            // opens a stream using the previous connection object
            // play the published stream "my_cam"
            var viewer:NetStream = new NetStream(my_nc);
            viewer.play("my_cam");
        }
       
        public function onBWDone():void
        {
        }
       
        private function netStatusHandler(event:NetStatusEvent):void {
            switch (event.info.code) {
                case "NetConnection.Connect.Success":
                    startLive();
                    break;
                case "NetStream.Play.StreamNotFound":
                    trace("Stream not found");
                    break;
            }
        }

        private function securityErrorHandler(event:SecurityErrorEvent):void {
            trace("securityErrorHandler: " + event);
        }
    }
}
    This topic has been closed for replies.

    3 replies

    Participating Frequently
    April 21, 2009

    Try registering some netstream handlers to see what is going on.

    netStream.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);

    private function netStatusHandler(event:NetStatusEvent) :void
    {
         if(event.info.code == "NetStream.Play.Stop")
            ......

           .....

          etc....

    }

    You might also want to declare your streams, and assign them later.

    public class streamer extends Sprite
    {
            var vid:Video;
            private var cam:Camera;
            private var t:Timer = new Timer(1000);
            private var my_nc:NetConnection = new NetConnection();

            private var publisher:NetStream;

            private var viewer:NetStream;

            ....

    }

    C_Re_eYeAuthor
    Participant
    April 21, 2009

    Thanks

    I figured it out guys!

    look at my code:

    var publisher:NetStream = new NetStream(my_nc);

    this netstream gets deleted by the garbage collection

    i declared it globally and everything is fine now

    April 20, 2009

    Without looking at the code, I'd remove things from the bigger FLA file in a methodical way to try to determine where the problem is. OR you could start with the simplest FLA possible and add things back to the FLA to try to determine where the problem is.

    HTH,

    Jody

    C_Re_eYeAuthor
    Participant
    April 16, 2009

    HEY!

    broadcasting stops in the smaller fla too!

    i use media server developer edition

    do i need to add somethings to the code?

    do i need to change server settings somehow?