基于red5的flex视频研究(2)
这两天又完善了下细节性的东西,包括上下线提醒,视频请求交互……本以为很容易的,但是做的过程中还是发现了许多问题,同时也有一些疑问,在此和大家分享一下。
上下线提醒:
当有用户进入的时候,服务器端的方法appConnect()自动执行,可以在此方法中加入向其它在线的用户广播上线的方法.在遍历所有在线用户时,我开始用的是:
Iterator<IConnection> it = scope.getConnections();
Iterator it = scope.getConnections().iterator();while(it.hasNext()){ Set connections = (Set)it.next(); IConnection conn = (IConnection)connections.iterator ().next(); callClientLogin(conn,name); //此方法将调用客户端上线提醒方法}
//客户端: //邀请他人视频 private function inviteVideo():void{ var To:String = userList.selectedItem.username; videoUsers[1] = To; chatCon.htmlText += "您选择的对象是:"+ To; nc.call("videoInvite",null,videoUsers[0],videoUsers[1]); Alert.show("正在等待对方连 接...","haha",Alert.CANCEL,this,canelHander); } //视频请求交互 public function IsVideoInvite(from:String):void{ Alert.show(from+"邀请你视频,是否同意?","是吗",Alert.YES|Alert.NO,this,alertClientHander); } //被邀请方同意视频 private function alertClientHander(event:CloseEvent):void{ if(event.detail==Alert.YES){ nc.call("videoInviteSuccess",null,videoUsers[0]); } getVideo(); else{ } } //获取邀请方视频 private function getVideo():void{ remoteStream = new NetStream(nc); remoteStream.bufferTime=1; //缓冲1秒再播放,保证视频流畅 otherVideo.width=remoteVideo.width; otherVideo.height=remoteVideo.height; otherVideo.attachNetStream(remoteStream); remoteStream.play(userName); remoteVideo.addChild(otherVideo); } //邀请方获取被邀请方视频 private function getOtherVideo(user:String):void{ remoteStream = new NetStream(nc); remoteStream.bufferTime=1; //缓冲1秒再播放,保证视频流畅 otherVideo.width=remoteVideo.width; otherVideo.height=remoteVideo.height; otherVideo.attachNetStream(remoteStream); remoteStream.play(user); remoteVideo.addChild(otherVideo); }
....... nc.addEventListener(AsyncErrorEvent.ASYNC_ERROR, _asyncHandler); ....... //异步错误 private function _asyncHandler(evt:AsyncErrorEvent) { chatCon.htmlText += "异步错误!\n"; }