一聚教程网:一个值得你收藏的教程网站

热门教程

flash制作在线视频会议程序

时间:2022-07-02 17:04:47 编辑:袖梨 来源:一聚教程网

flash制作在线视频会议程序

package {
        import flash.display.Sprite;
        import flash.net.NetConnection;
        import flash.net.NetStream;
        import flash.events.NetStatusEvent;
        import flash.media.Video;
        import flash.media.Camera;
        import flash.events.ActivityEvent;

        public class videoChat extends Sprite
        {
                [ SWF( backgroundColor='0xdedede', frameRate='500', , ) ]//设置swf参数
                private var conn:connFcs,camera:Camera,videoIn:Video,outStream:NetStream,inStream:NetStream;
                public function videoChat()
                {
                        var url:String="rtmp:/test_chat";//连接地址
                        var conn:connFcs=new connFcs(url);//建立连接,这个类在最下面的
                        this.conn=conn;
                        conn.addEventListener(NetStatusEvent.NET_STATUS,NetStatusEventHandel);//监视连接状态
                }
                private function NetStatusEventHandel(event:NetStatusEvent):void
                {
                        trace(event.info.code);
                        if(event.info.code=="NetConnection.Connect.Success")//如果连接成功
                        {
                                init();//初始化
                                publishStream();//发布视频
                        }
                }
                private function publishStream():void
                {
                        outStream=new NetStream(conn);
                        outStream.publish("test","record");//发布参数,test为视频名,record表示是要保存的,如果不保存用live
                        outStream.attachCamera(camera);
                        inVideo();
                }
                private function inVideo():void
                {//接收视频
                        inStream=new NetStream(conn);
                        inStream.play("test");
                        videoIn.attachNetStream(inStream);
                }
                private function init():void
                {
                        videoIn=new Video();//添加一个视频为了接收
                        addChild(videoIn);
                       
                        camera=Camera.getCamera();//得到摄像头
                        if(camera!=null)//如果有摄像头,添加一个视频到显示
                        {
                                camera.addEventListener(ActivityEvent.ACTIVITY,activityHandler);
                                var video:Video= new Video(camera.width * 2, camera.height * 2);
                                video.x=camera.width;
                                video.y=camera.height;
                                video.attachCamera(camera);
                            addChild(video);
                        }else{trace("you need camera!");}
                       
                }
                private function activityHandler(event:ActivityEvent):void
                {
                        trace('activityHandler'+event);
                }
               
        }
       
}
        import flash.net.NetConnection;
        import flash.net.ObjectEncoding;
       

class connFcs extends NetConnection
{
        private var url:String
        public function connFcs(url:String)
        {
                objectEncoding=ObjectEncoding.AMF0;//连接fcs需要设置这个
                this.url=url;
                connect(url);//开始连接
        }
}
flash制作在线视频会议程序

热门栏目