简体   繁体   中英

Webcam pool using Flash Media Server

I have an application where users can log in and connect to the Flash media server. Once they have been connected, anyone can view their webcam.

For example, lets say Bob and Sally log on to the website and their cameras are now being streamed. Bob can view Sally's webcam stream at http://www.example.com?cam=sally and Sally can view Bob's webcam stream at http://www.example.com?cam=bob

Use this code to broadcast webcam stream to FMS:

    var nc : NetConnection = new NetConnection( );
        nc.client = this;
        nc.addEventListener(NetStatusEvent.NET_STATUS, statusHandler );
        nc.connect( "rtmp://your-fms-server-url/your-application" );

    var cam : Camera = Camera.getCamera( );
        cam.setMode( 640, 480, 20 );

    var ns : NetStream;

    function statusHandler ( eventOBJ : NetStatusEvent )
    {
        if ( eventOBJ.info.code == "NetConnection.Connect.Success" )
        {
            ns = new NetStream( nc );
            ns.attachCamera( cam );
            ns.publish( "your-stream-name" );
        }
    };

The receiver is simliar, except a few lines:

    // to the declaration section:
    var video : Video = new Video( );

    // code in the statusHandler method:
    if ( eventOBJ.info.code == "NetConnection.Connect.Success" )
    {
        ns = new NetStream( nc );
        ns.play( "your-stream-name", -1 );
        video.attachNetStream( ns );    
        addChild( video );
    }

And you simply pass the name of the desired stream in flashvars. For example if you use this url: www.yourdomain.com/chat.php?cam=Sally, in this case pass the cam parameter to the SWF client, and use in the following form:

    ns.play( this.loaderInfo.parameters.cam , -1 );

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM