使用像youtube这样的flash媒体播放器来播放来自fms的netsteam

时间:2012-08-23 11:16:48

标签: actionscript-3 flash flash-media-server

我正在使用adobe FMS 4.5从网络摄像头录制视频,并在同一应用程序中从fms播放netsream。

我的客户端Action Script就像

package
{
    import fl.controls.Button;
    import flash.display.Sprite;
    import flash.net.NetConnection;
    import flash.net.NetStream;
    import flash.events.NetStatusEvent;
    import flash.events.MouseEvent;
    import flash.events.Event;
    //import flash.net.ObjectEncoding;
    import flash.media.Camera;
    import flash.media.Microphone;
    import flash.media.Video;



public class mytest3 extends Sprite
    {

        private var nc:NetConnection;
        private var ns:NetStream;
        private var rtmpNow:String;
        private var msg:Boolean;
        private var cam:Camera;
        private var mic:Microphone;
        private var vid1:Video;
        private var recordBtn:Button;
        private var stopBtn:Button;
        private var playBackBtn:Button;
        private var textInput:TextInput;
        private var timestamp:Date    = new Date();
        private var fileName:String;


        //Constructor
        function mytest3 ()
        {
            //NetConnection.defaultObjectEncoding = flas    h.net.ObjectEncoding.AMF0;
            nc=new NetConnection();
            nc.addEventListener (NetStatusEvent.NET_STATUS,checkConnect);
            rtmpNow="rtmp://localhost/test1";
            //rtmpNow="rtmp://192.169.1.25/test1";

            nc.connect (rtmpNow);
            addMedia ();
            addUI ();
            recordBtn.addEventListener (MouseEvent.CLICK,startRecord);
            stopBtn.addEventListener (MouseEvent.CLICK,stopRecord);
            playBackBtn.addEventListener(MouseEvent.CLICK,playBack);
    }

        private function addMedia ():void
        {
            cam=Camera.getCamera();
            cam.setMode (240,180,24);
            cam.setQuality (0,100);
            mic=Microphone.getMicrophone();
            vid1=new Video(cam.width,cam.height);
            vid1.attachCamera (cam);
            addChild (vid1);
            vid1.x=100;
            vid1.y=50;
        }

        private function addUI ():void
        {
            recordBtn=new Button();
            recordBtn.label="Start Recording";
            recordBtn.x=100;
            recordBtn.y=50+(cam.height) +5;
            recordBtn.width=70;
            addChild (recordBtn);

            stopBtn=new Button();
            stopBtn.label="Stop Recording";
            stopBtn.x=recordBtn.x+85;
            stopBtn.y=recordBtn.y;
            stopBtn.width=75;
            addChild (stopBtn);

            playBackBtn=new Button();
            playBackBtn.label="PlayBack";
            playBackBtn.x=stopBtn.x+85;
            playBackBtn.y=recordBtn.y;
            playBackBtn.width=75;
            addChild(playBackBtn);

        }

        private function checkConnect (e:NetStatusEvent):void
        {
            msg=(e.info.code=="NetConnection.Connect.Success");
            if (msg)
            {
                ns = new NetStream(nc);
            }
        }

        private function startRecord (e:Event):void
        {
            if (ns)
            {
                //recordBtn.label="Recording";
                recordBtn.visible=false;
                ns.attachAudio (mic);
                ns.attachCamera (cam);
                fileName = String("videos"+timestamp.getTime());
                ns.publish(fileName,"record")

            }
        }

        private function stopRecord (e:Event):void
        {
            //recordBtn.label="Recorded"
            recordBtn.visible=false;;
            stopBtn.label="Stoped";
            ns.close ();
        }
        private function playBack(e:Event):void 
        {
            playBackBtn.label="Playing Back";
            stopBtn.visible=false;
            var nsPlayer:NetStream = new NetStream(nc);
            //nsPlayer.play("my.flv");
            var vid:Video = new Video(cam.width,cam.height);
            vid.x = playBackBtn.x+30;
            vid.y = vid1.y;
            vid.attachNetStream(nsPlayer);
            nsPlayer.play(fileName);
            vid.smoothing=true;
            addChild(vid);
        }
    }
}  

录制和播放工作正常。 我希望它在回放时看起来像youtube视频,其中包含播放,暂停,搜索栏等控件。

1 个答案:

答案 0 :(得分:0)

你需要自己创建这些控件,或使用flash组件(FLVplayback)或Strobe(虽然我认为没有一种简单的方法可以在现有闪存中嵌入闪光灯与swc项目,也许其他人可以评论或编辑这个来澄清那个)

可以为FLVplayback设置外观以查看您想要的内容