每天一点学FMS(二)文字+视频语音

              每天一点学FMS(二)文字+视频语音

FMS服务器的设置简单的仿照(一)就可以了,这段代码延续(一),加上了视频和语音发布,主要用到netstream.publish()方 法,该方法也可以用于视频在线录制,除了检测摄相头和MIC状态的代码外,就增加了十几行的视频发布代码,有关摄相头和MIC的详细设置我并没有写,只是 让大家看清楚它的工作原理,没有摄相头的朋友(我就没有摄相头)可以这样测试:打开麦克风说话,如果能听到回音就说明发布成功了
复制内容到剪贴板
代码:
//建立与服务器的连接.
var sv_uri:String = "rtmp:/recordstream";
var my_nc:NetConnection = new NetConnection ();
my_nc.connect (sv_uri);
//新建共享对象;
my_nc.onStatus = function (thisObj:Object){
        if (thisObj.code == "NetConnection.Connect.Success"){
                info_txt.text = "连接服务器成功!!";
                info_txt.textColor = 0x66CC00;
        }
        else{
                info_txt.text = "连接服务器失败!!"
                info_txt.textColor = 0xFF0000;
        }
}
var user_rso:SharedObject = SharedObject.getRemote ("chat_rso", my_nc.uri, true);
user_rso.connect (my_nc);
//建立摄相头和麦克风对象
this.cam = Camera.get();
this.mic = Microphone.get();
videobox.attachVideo(this.cam);
videobox.attachAudio(this.mic);
send_ns = new NetStream(my_nc);
send_ns.attachVideo(this.cam);
send_ns.attachAudio(this.mic);
send_ns.publish("humorguy");
get_ns = new NetStream(my_nc);
get_ns.play("humorguy");
videobox2.attachVideo(get_ns);
//更新聊天内容
user_rso.onSync = function (){
                chatOutput_txt.text += newline+this.data.chatname +":" + this.data.chatcontent;
                chatOutput_txt.scroll = chatOutput_txt.maxscroll+1;//确保最新消息能显示在输出框里
}
//回车键发送聊天内容
function myOnKeyDown() {
    if (Key.getCode() == 13) {
                if(chatInput_txt.text != undefined && chatInput_txt.text != user_rso.data.chatcontent){
                    Selection.setFocus(chatInput_txt);
                        user_rso.data.chatcontent = chatInput_txt.text;
                        if(name_txt.text != "" && name_txt.text != user_rso.data.chatname){
                                user_rso.data.chatname = name_txt.text;
                                }
                }
    }
}
var myListener:Object = new Object();
myListener.onKeyDown = myOnKeyDown;
Key.addListener(myListener);
//构造检测摄相头和麦克风状态的函数
function checkforCam_Mic() {
        camArray = Camera.names;
        micArray = Microphone.names;
        if (camArray.length>=1) {
                temp_cam = Camera.get();
                if (temp_cam == -1) {
                        camInfo_txt.text = '视频设备正忙!';
                        camInfo_txt.textColor = 0xFFCC00;
                } else {
                        camInfo_txt.text = '视频设备可用!';
                        camInfo_txt.textColor = 0x66CC00;
                }
                delete temp_cam;
        } else if (camArray.length == 0) {
                camInfo_txt.text = '没有视频设备!';
                camInfo_txt.textColor = 0xFF0000;
        }
        //检测麦克风状态
        if (micArray.length>=1) {
                temp_mic = Microphone.get();
                if (temp_mic == -1) {
                        camInfo_txt2.text = '麦克风正忙!';
                        camInfo_tx2t.textColor = 0xFFCC00;
                } else {
                        camInfo_txt2.text = '麦克风可用!';
                        camInfo_txt2.textColor = 0x66CC00;
                }
                delete mic_cam;
        } else if (micArray.length == 0) {
                camInfo_txt2.text = '没有麦克风!';
                camInfo_txt2.textColor = 0xFF0000;
        }
}
checkforCam_Mic();

你可能感兴趣的:(工作)