`
ljz0898
  • 浏览: 227247 次
  • 性别: Icon_minigender_1
  • 来自: 海南海口
社区版块
存档分类
最新评论

as3.0+fms实现一个视频交流系统

阅读更多
这些都是很久以前玩flash的时候写的,为了怕掉,不知道以后还用没有用,毕竟是自己写的很值的留念哦!所以发上来备份一下,同时给需要的一个小小帮助!
学了as3 就接着学了fms:做了一个视频交流系统;写了3个类!
videoChat.as



package {
    import flash.display.*;
    import flash.text.*;
    import flash.net.*;
    import flash.events.*;
    import flash.errors.*;
    import flash.system.*;
    import fl.managers.StyleManager;
    import flash.media.*;
    import fl.controls.List;
    import fl.data.DataProvider;
    import fl.controls.TextArea;
    public class videoChat extends Sprite {
        public var IP:String;
        public var fmsPath:String;
        public var myNC:NetConnection;
        public var myNS:NetStream;
        private var mySubNS:NetStream;
        public var userName:String;
        public var mySO:SharedObject;
        public var peopleArray:Array;
        public var tmpName:String;
        public var msg:String
        public var now:Date;
        private var myCam:Camera;
        private var myMic:Microphone;
        public function videoChat() {
            init();
            startConnect();
        }
        public function init() {
            var myTF:TextFormat=new TextFormat();
            myTF.size=12;
            StyleManager.setStyle("textFormat",myTF);//不理解的代码
            IP="127.0.0.1";//不理解的代码
            fmsPath="rtmp://"+IP+"/videoChat";//不理解的代码
            userName="guest"+int(Math.random()*1000);
            userName1.text=userName;
            userName2.text="所有人";
            now=new Date();
            peopleList.addEventListener(MouseEvent.CLICK,selectChatTo);
            peopleList.addEventListener(MouseEvent.DOUBLE_CLICK,getVideo);
        }
        public function startConnect() {
            myNC=new NetConnection;
            myNC.client=this;
            myNC.objectEncoding=ObjectEncoding.AMF3;
            myNC.addEventListener(NetStatusEvent.NET_STATUS,netStatus);
            myNC.addEventListener(AsyncErrorEvent.ASYNC_ERROR,asyncError);
            myNC.addEventListener(SecurityErrorEvent.SECURITY_ERROR,securityError);
            myNC.connect(fmsPath,userName);
        }
        public function netStatus(event:NetStatusEvent):void {
            switch (event.info.code) {
                case "NetConnection.Connect.Success" :
                    chatContent.htmlText+="连接成功";
                    setMySO();
                    sendBtn.addEventListener(MouseEvent.MOUSE_DOWN,sendMsgByMouse);
                    stage.addEventListener(KeyboardEvent.KEY_DOWN,sendMsgByKey);
                    publishStream();
                    break;
                case "NetConnection.Connect.Failed" :
                    chatContent.htmlText+="连接失败";
                    break;
                case "NetConnection.Connect.Rejected" :
                    chatContent.htmlText+=event.info.application.message;
                    break;
            }
        }
        public function securityError(event:SecurityErrorEvent):void{
            chatContent.htmlText+="安全性错误"}
            public function setMySO():void{
                mySO=SharedObject.getRemote("mySO",myNC.uri,false)
                mySO.addEventListener(SyncEvent.SYNC,mySoSync)
                mySO.connect(myNC)}
                public function asyncError(event:AsyncErrorEvent):void{}
                public function mySoSync(e:SyncEvent):void{
                    peopleArray=new Array
                    for (var tmp in mySO.data){
                        peopleArray.push(tmp)}
                        var tmpDP:DataProvider=new DataProvider
                        for(var i=0;i<peopleArray.length;i++){
                            tmpName=peopleArray[i]
                            tmpDP.addItem({label:tmpName})}
                            tmpDP.sortOn("label")//很有可能有错
                            tmpDP.addItemAt({label:"所有人"},0)
                            peopleList.dataProvider=tmpDP
                            }
                            public function sendMsgByKey(event:KeyboardEvent):void{
                                if(event.keyCode==13){
                                    sendMsg()}}
                                    public function sendMsgByMouse(event:MouseEvent):void{
                                        sendMsg()}
                                        public function sendMsg():void{
                                            if(willSendMsg.length>0){
                                                if(userName2.text==userName1.text){
                                                    chatContent.htmlText+="你不能对你自己发言"+"\n"
                                                    chatContent.verticalScrollPosition=chatContent.maxVerticalScrollPosition}
                                                    else {
                                                        var allpeople:Array=new Array
                                                        for(var i=0;i<peopleList.length;i++){
                                                            if(peopleList.getItemAt(i).label!="所有人"&&peopleList.getItemAt(i).label!=userName1.text){
                                                                allpeople.push(peopleList.getItemAt(i).label)}}
                                                                msg="<font color='#ff0000'>"+userName1.text+"</font)"+"对"+"<font color='#ff0000'>"+userName2.text+"</font>"+"说"+"("+"<font color='#0000ff'>"+now.getHours()+":"+"</font>"+"\n"+willSendMsg.text+"\n"
                                                                if(userName2.text==null)
                                                                {
                                                                    userName2.text="所有人"
                                                                    }
                                                                    myNC.call("msgFromClient",null,userName1.text,userName2.text,msg,allpeople)
                                                                    chatContent.htmlText+=msg
                                                                    chatContent.verticalScrollPosition=chatContent.maxVerticalScrollPosition
                                                                    willSendMsg.text=""
                                                                    }}}
                                                                    public function msgFromSrvr(msg){
                                                                        trace(msg)
                                                                        chatContent.htmlText+=msg
                                                                        chatContent.verticalScrollPosition=chatContent.maxVerticalScrollPosition}
                                                                        private function selectChatTo(event:MouseEvent):void{
                                                                            userName2.text=peopleList.selectedItem.label}
                                                                            private function publishStream():void{
                                                                                myCam=Camera.getCamera()
                                                                                myMic=Microphone.getMicrophone()
                                                                                liveVideo.attachCamera(myCam)
                                                                                myNS=new NetStream(myNC)
                                                                                myNS.client=this
                                                                                myNS.addEventListener(NetStatusEvent.NET_STATUS,netStatus)
                                                                                myNS.addEventListener(AsyncErrorEvent.ASYNC_ERROR,asyncError)
                                                                                myNS.attachAudio(myMic)
                                                                                myNS.attachCamera(myCam)
                                                                                myNS.publish(userName1.text,"live")
                                                                                }
                                                                                private function getVideo(event:MouseEvent):void{
                                                                                    if(userName2.text!=userName1.text){
                                                                                        whoseVideo.text=userName2.text+"的视频 "
                                                                                        mySubNS=new NetStream(myNC)
                                                                                        mySubNS.client=this
                                                                                        mySubNS.addEventListener(NetStatusEvent.NET_STATUS,netStatus)
                                                                                        mySubNS.addEventListener(AsyncErrorEvent.ASYNC_ERROR,asyncError)//这个函数不是很清楚
                                                                                        liveVideo.attachNetStream(mySubNS)
                                                                                        mySubNS.play(userName2.text)}
                                                                                        else{
                                                                                            mySubNS.close()
                                                                                            liveVideo.clear()
                                                                                            whoseVideo.text="我的视频"
                                                                                            liveVideo.attachCamera(myCam)}}
                                  
  
  
    }
}


Myself.as


package{
    import flash.display.Sprite
    import flash.events.MouseEvent
    import flash.net.ObjectEncoding
    import flash.net.NetConnection
    import flash.net.NetStream
    import flash.text.TextField
    import fl.controls.List
    public class extends  Myself extends Sprite{
        private var myNC:NetConnection
        private var myNS:NetStream
        private var userName1:String
        private var userName2:String
        public function Myself(){
            init()
            started()}
            public function init(){
                }}}

main.asc



application.onAppStart=function(){
    trace("程序已启动")
    list=new Object()
    application.mySO=SharedObject.get("mySO",false)}
    application.onConnect=function(newClient,userName){
        trace("有新的用户连接:"+userName)
        if(list[userName]==null){
                              list[userName]=newClient
                              newClient.userName=userName
                            
                              this.acceptConnection(newClient)
                              application.mySO.setProperty(newClient.userName,userName)
                              newClient.msgFromClient=function(user1,user2,msg,allpeople){for(var i=0;i<allpeople.length;i++){
                                  application.list[allpeople[i]].call("msgFromSrvr",null,msg)}}}
                                  else {
                                      var err=new Object()
                                      err.message="对不起,该用户已存在"
                                      application.rejectConnection(newClient,err)}}
                                      application.onDisconnect=function(oldUser){
                                          application.mySO.setProperty(oldUser.userName,null)
                                          list[oldUser.userName]=null
                                          delete list[oldUser.userName]}
分享到:
评论

相关推荐

    FMS聊天室+AS3.0

    【描述】"FMS+AS3.0多人聊天室源文件下载"说明我们可以获取到实现这一功能的完整源代码。这意味着开发者或学习者可以深入研究代码结构,理解其工作原理,并根据需要进行自定义修改或扩展。ActionScript 3.0是Flash...

    Flex +FMS实现视频聊天

    Flex+FMS写的视频聊天,在本机亲测通过。但唯一不足得是在别的机子上连接不成功。我也不知道为什么。望有才之士能完善。huzhaohui1992@qq.com 如能完善,请给我邮箱一份,在下感激不尽。

    flex+fms实现视频直播源码

    这个项目提供了一个简单示例,演示了如何利用Flex进行摄像头和音频的捕获与录制,以及如何将这些内容实时推送到FMS服务器进行广播。下面将详细介绍这个系统的工作原理和关键知识点。 1. **Flex**:Flex是Adobe推出...

    FMS3.0实现视频会议代码

    在本文中,我们将深入探讨如何使用Flex 3.0和FMS3.0(Flash Media Server 3.0)来实现视频会议系统。对于初学者来说,这是一个极具价值的实践项目,可以让你对实时多媒体通信有更深入的理解。 首先,让我们了解一下...

    asp+fms聊天室

    总的来说,ASP+FMS语音聊天室是一个结合了前后端技术的实时通讯应用,它利用ASP处理后端逻辑,通过FMS提供高效的音视频流服务,从而实现流畅的在线聊天体验。在深入研究和使用这套系统时,开发者需要熟悉ASP编程、...

    基于FLASH+XML+FMS的视频点播.pdf

    ### 基于FLASH+XML+FMS的视频点播系统设计与实现 #### 一、引言 视频点播(Video On Demand, VOD)作为现代远程教育的关键组成部分,在提高教育资源利用率方面扮演着极其重要的角色。传统的视频点播系统多依赖于...

    as3 + fms3聊天室

    【标题】"AS3 + FMS3聊天室"是一个基于ActionScript 3(AS3)编程语言和Flash Media Server 3(FMS3)技术构建的在线聊天室应用。这个项目提供了一个简单但实用的平台,让多个用户可以实时交流分享信息。 【描述】...

    thikphp+FMS 直播系统.rar_fms php_php 直播_thikphp+FMS 直播系统_直播_视频直播

    本文将深入探讨如何利用thikphp框架与FMS(Flash Media Server)构建一个高效、稳定的视频直播系统。 thikphp是一款流行的PHP开发框架,以其简洁的代码结构、高效的性能和丰富的功能著称。它提供了一套完整的MVC...

    as3+fms连线对战中国象棋

    【标题】"as3+fms连线对战中国象棋"是一个基于ActionScript 3(AS3)编程语言和Flash Media Server(FMS)技术实现的在线中国象棋游戏项目。这个项目允许玩家通过网络进行实时对战,共享游戏体验。 【AS3】是Adobe ...

    FME3.0(FMS直播采集推送工具,直播系统必备)

    Flash Media Live Encoder v3.0,FMS直播采集推送工具,直播系统必备。

    phpvod+fms4.5局域网视频点播系统搭建-附件资源

    phpvod+fms4.5局域网视频点播系统搭建-附件资源

    flash+fms游戏大厅房间源程序

    总的来说,"Flash+FMS游戏大厅房间源程序"展示了如何利用Flash的交互性和FMS的实时能力,构建一个功能完备、用户体验良好的在线游戏环境。虽然随着HTML5等新技术的发展,Flash的地位有所下降,但其在实时游戏领域的...

    as3+FMS以字节流的方式从服务器读取swf、图片、文本等文件

    主要功能是从服务端以字节流的方式加载swf、图片、文本等文件,理论上讲可以用做swf文件...另外,以字节流加载本地swf或在本地共享对象中存取swf、图片、文本等文件,原理与这个例子相同,有兴趣的网友可以自己试一试。

    flash+fms2视频聊天室-附带源码

    flash+fms2视频聊天室-附带源码 源码在 html页面上有下载的超链接

    FLASH+php WEBGame 45度地图切换 多人游戏社区(源码+fms服务端)开源项目

    本引擎QQ交流群:73944013 FLASH+php WEBGame 45度地图切换 多人游戏社区 FLASH人物行走 FLASH人物8方向寻路 在线聊天 (源码+fms服务端)开源项目 游戏截图: http://www.365tt1.com/ads/RGP/001.jpg ...

    flash+FMS斗地主源程序

    1. `arithmetic.as`:这可能是一个AS(ActionScript)文件,ActionScript是Flash中的编程语言,可能包含了游戏逻辑和算法,如发牌规则、计分系统等。 2. `ddz.fla`:FLA文件是Flash的源文件,包含了图形、动画和...

    flash+FMS斗地主游戏源程序

    【标题】:“flash+FMS斗地主游戏源程序”是一个基于Adobe Flash技术和FMS(Flash Media Server)开发的在线斗地主游戏项目。这个源程序是开发者为了分享和学习技术而公开的,被称为“吐血献出”,暗示了开发者在这...

    FMS多人视频会议系统

    【FMS多人视频会议系统】是一个利用Flash Media Server (FMS) 技术构建的高效、稳定的多人在线视频交流平台。这个系统的核心是FMS,它是由Adobe开发的一款服务器软件,专门用于实时流媒体处理,支持音频、视频的直播...

    利用fms实现视频聊天程序

    本教程将详细介绍如何利用FMS构建一个简单的视频聊天程序。 【描述】:“利用FMS实现视频聊天程序,希望对和我一样的菜鸟们能有些帮助” 对于初学者来说,理解并应用FMS可能会显得有些复杂,但通过逐步学习和实践...

    FMS3系列(五):通过FMS实现时时视频聊天(Flash|Flex)

    2. **创建流**:在服务器端,通过FMS API创建一个或多个流,用于接收和发送音视频数据。 3. **捕捉与发送**:在客户端捕获用户的摄像头和麦克风输入,封装成RTMP数据包,然后发送到服务器。 4. **接收与播放**:...

Global site tag (gtag.js) - Google Analytics