Flex 第四章(捕获实时视频、向实时视频中添加DVR特征)

转:http://hi.baidu.com/airlonepig/item/8d7f33edaf91501e570f1d62

 

第四章(捕获实时视频、向实时视频中添加DVR特征)

package {
    import flash.display.MovieClip;
    import flash.net.NetConnection;
    import flash.events.NetStatusEvent;
    import flash.net.NetStream;
    import flash.media.Video;
     import flash.media.Camera;
    import flash.media.Microphone;

    public class PublishLive extends MovieClip
    {
          var nc:NetConnection;
          var ns:NetStream;
          var nsPlayer:NetStream;
          var vid:Video;
          var vidPlayer:Video;
          var cam:Camera;
          var mic:Microphone;

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

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

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

          private function displayPublishingVideo():void {
               vid = new Video(cam.width, cam.height);
               vid.x = 10;
               vid.y = 10;
               vid.attachCamera(cam);
               addChild(vid);
          }

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



向实时视频中添加DVR特征
DVR(digital video recorder)让观察者可以暂停实时视频并从暂停点恢复播放。也可以回退,播放录制的部分,跳转。

通过动态流使用DVR
为了能够绝对时间编码,在应用文件夹创建一个"Application.xml"文件,添加以下内容:
<Application>
     <StreamManager>
          <Live>
               <AssumeAbsoluteTime>true</AssumeAbsoluteTime>
          </Live>
     </StreamManager>
</Application>

 

你可能感兴趣的:(Flex 第四章(捕获实时视频、向实时视频中添加DVR特征))