zoukankan      html  css  js  c++  java
  • 一段获取视频的简易方法

    <?xml version="1.0" encoding="utf-8"?> 
    <!-- 
    //////////////////////////////////////////////////////////////////////////////// 
    // 
    // Copyright (C) 2007 royllik. 
    //通用视频组件,有local和remote两种状态,这里的代码不需要修改 
    // 
    //////////////////////////////////////////////////////////////////////////////// 
    --> 
    <mx:Panel xmlns:mx="http://www.adobe.com/2006/mxml" 
    styleName="opaquePanel" layout="absolute" 
    title="{thisTitle}" 
    horizontalScrollPolicy="off" verticalScrollPolicy="off"> 

    <mx:Script> 
    <![CDATA[ 
    import flash.external.ExternalInterface; 
    import mx.controls.Alert; 
    import mx.core.UIComponent; 
    import mx.managers.PopUpManager;
    import flash.media.*; 
    import avchat.chatRoom.utils.ModelLocator; 
    import avchat.chatRoom.ui.event.CustomEvent; 
    private var model:ModelLocator = ModelLocator.getInstance(); 


    [Bindable] 
    public var thisTitle:String;

    public var reciveStream:String; 

    private var camera:Camera; 
        private var mic:Microphone; 
        private var outns:NetStream; 
    private var inns:NetStream; 
        

        private var video:Video; 
        private var videoHolder:UIComponent; 
        
        
        protected override function createChildren():void { 
    super.createChildren();
    this.titleBar.addEventListener(MouseEvent.MOUSE_DOWN, onDown); 
    this.titleBar.addEventListener(MouseEvent.MOUSE_UP, onUp); 


        private function onDown(evt:Event):void 
    this.startDrag(); 
    private function onUp( evt:Event ):void 
    this.stopDrag(); 
        

        //断开流媒体连接,并删除videoHolder 
        public function stopAv():void 
        { 
        if(outns) 
        {   
        //outns.pause(); 
        outns.close(); 
        //Alert.show("关闭了" + outns); 
        } 
        if(inns) 
        {    
        //inns.pause(); 
        inns.close(); 
        //Alert.show("关闭了" + inns); 
        } 
        if(video)  
        video.clear(); 
        this.removeAllChildren(); 
        
        //this.removeChild(videoHolder); 
        thisTitle = ""; 
        } 
        
        
        //设置麦克风 
    private function setmic():void 
        {   
        mic.gain = 70; 
    mic.rate = 11; 
    mic.setUseEchoSuppression(true); 
    mic.setSilenceLevel(5, 1000); 
    //mic.setLoopBack(false); 
       
        } 
        
        //设置摄像头 
        private function setCam():void 
        { 
        camera.setKeyFrameInterval(30); 
        camera.setMode(320, 240, 25, true); 
    camera.setQuality(0,85); 
    //camera.setLoopback(true); 
        } 
        
        //推送自己的流媒体 
        public function publishAV(recordorlive:String, int, height:int):void 
        {   
        //发送视频,视频的名字是 发送人的ID+_+当前ROOM的名字 
        var streamName:String = model.myself.userId + "_" + model.currentRoom; 
        //trace("streamName:" + streamName); 
        if(outns) 
        outns.close(); 
        outns = new NetStream(model.fmsserver.nc); 
        outns.client = this; 
        //outns.checkPolicyFile = true; 
        if (Camera.names.length > 0){ 
    camera = Camera.getCamera(); 
        } 
        //trace(camera); 
        if (camera == null) 
        { 
        mic = Microphone.getMicrophone(); 
        setmic(); 
        
        outns.attachAudio(mic); 
        //这里要以后要根据要求,决定是否录制 
        //Alert.show("streamName:"+ streamName); 
        outns.publish(streamName, recordorlive); 
      
        } 
        else 
        { 
        mic = Microphone.getMicrophone(); 
        setmic(); 
        setCam(); 
        outns.attachAudio(mic); 
        outns.attachCamera(camera); 
        //这里 要以后要根据要求,决定是否录制 
        outns.publish(streamName, recordorlive); 
        //Alert.show("streamName:"+ streamName); 
        
        } 
        //Alert.show("自己发送" + streamName); 
        videoHolder = new UIComponent(); 
    videoHolder.setActualSize(width,height); 
    video = new Video(width, height); 
        video.attachCamera(camera); 
        videoHolder.addChild(video); 
        this.addChild(videoHolder); 

        } 
        //接收视频,视频的名字是 发送人的ID+_+当前ROOM的名字 
        public function reciveAV(int,height:int):void 
        { 
        //trace(this.reciveStream); 
        //var reciveStream:String = thisUserId + "_" + model.currentRoom; 
        //Alert.show("reciveStream: "+reciveStream); 
        if(inns) inns.close(); 
        inns = new NetStream(model.fmsserver.nc); 
        //inns.checkPolicyFile = true; 
        inns.play(reciveStream); 
        //Alert.show("收到了" + reciveStream); 
        inns.client = this; 
        videoHolder = new UIComponent(); 
        videoHolder.setActualSize(width,height); 
        video = new Video(width, height); 
        video.attachNetStream(inns); 
        videoHolder.addChild(video); 
    this.addChild(videoHolder); 
        } 


    ]]> 
    </mx:Script> 
    </mx:Panel> 
  • 相关阅读:
    线程死的时候会调用自己的notifyAll方法,join会执行结束。
    NIO中SocketChannel read()返回0的原因
    用bytebuffer进行文件的读写代码段
    java线程池参数含义
    4.3list集合
    4.1、2集合框架介绍
    3.9stingBuffer和stringBuilder
    3.8正则表达式
    3.6、7正则表达式
    3.3、4深度了解字符串
  • 原文地址:https://www.cnblogs.com/top5/p/1649986.html
Copyright © 2011-2022 走看看