隨筆 - 8  文章 - 55  trackbacks - 0
          <2025年6月>
          25262728293031
          1234567
          891011121314
          15161718192021
          22232425262728
          293012345

          常用鏈接

          留言簿(6)

          隨筆分類

          隨筆檔案

          文章分類

          文章檔案

          朋友的Blog

          最新評(píng)論

          閱讀排行榜

          評(píng)論排行榜

          【轉(zhuǎn)帖】實(shí)現(xiàn)了視頻私聊功能
          昨天匆忙實(shí)現(xiàn)了視頻私聊功能,今天把思路再整理下。順便和各位做個(gè)探討~
          我的基本思路是這樣的:
          1. 用戶登錄聊天室后在左邊的窗口自動(dòng)顯示視頻(如果檢測(cè)到有的話,如果沒(méi)有則顯示相關(guān)文字或圖片,這個(gè)暫時(shí)還沒(méi)有加);
          2. 點(diǎn)擊用戶列表中的相應(yīng)用戶名后取得對(duì)應(yīng)的視頻文件名,然后在右邊的窗口播放就可以了。
          看起來(lái)簡(jiǎn)單,其實(shí)不然哦~下面看詳細(xì)的分析
          注意:下面所有修改都是基于FlashCom 組件,相關(guān)的組件實(shí)現(xiàn)就不再詳細(xì)敘述。只是摘取視頻私聊相關(guān)部分分析。
          關(guān)于自動(dòng)開啟視頻的代碼修改:
          在av組件中的connect方法中添加
          1 : //av1_mc 是左邊視頻窗口的實(shí)例名稱
          2 : if (this.name=='av1_mc') this.startPublish();
          這個(gè)比較容易實(shí)現(xiàn),關(guān)鍵是私聊用戶的視頻顯示。
          因?yàn)锳VPresence組件的視頻發(fā)布是this.prefix + this.soName
          1 : this.ns.publish(this.prefix + this.soName);
          也就是說(shuō)是以窗口的實(shí)例名來(lái)定位播放的,要修改為針對(duì)用戶定位播放的方式,因此以上代碼改為
          1 : this.ns.publish(this.userID);
          這樣就是以用戶ID為文件名發(fā)布視頻文件,以便于我們下一步選擇不同的用戶來(lái)播放相應(yīng)的視頻。
          下一步,是修改接收視頻部分。
          原先接收的方式是當(dāng)前窗口接收,代碼為:
          1 : // Starts receiving a stream from another user
          2 : FCAVPresenceClass.prototype.startReceive = function() {
          3 : // trace('Start Receiving');
          4 : this.seat_video.attachVideo(this.ns);
          5 : this.ns.play(this.prefix + this.soName);
          6 : this.gotoAndStop('receiving');
          7 : this.onStartReceive();
          8 : };
          現(xiàn)在要改為指定播放窗口接收視頻(這里就是右邊的窗口了),而且要指明接收哪個(gè)用戶的,所以加傳遞用戶ID參數(shù),代碼改為:
          1 : FCAVPresenceClass.prototype.startReceive = function(userId) {
          2 : if (userId !=this.userID){ //如果選擇自己,則不再接收
          3 : this.seat_video.attachVideo(this.ns);
          4 : this.ns.play(userId);
          5 : this.gotoAndStop('receiving'); }
          6 : };
          接著要修改同步的部分,否則一旦視頻同步就會(huì)亂了。下面是修改后的代碼,比較下就知道了。
          01 : this.so.onSync = function(list) {
          02 : for (i in list) {
          03 : userID[this.data.speaker]=this.data.speakerID;//把用戶ID保存到數(shù)組
          04 : if (list[ i ].name == 'broadcast') {
          05 : if (this.data.broadcast && this.data.speakerID!=this.userID && this.data.speakerID == this.selectUserID) {
          06 : this.owner.startReceive(this.data.speakerID);
          07 : this.owner.username_txt.text = this.data.speaker;
          08 : } else {
          09 : this.owner.stopReceive();
          10 : this.owner.level.mask._height = 1;
          11 : this.owner.username_txt.text = '(Open)';
          12 : // Stop
          13 : }
          14 : }
          15 : }
          16 : };其中selectUserID就是我們點(diǎn)擊用戶列表后獲取到的值,要能夠獲取到這個(gè)值首先要在peopleList組件中保存用戶信息,在組件onchange事件觸發(fā)的時(shí)候可以獲取到用戶名。
          我在用戶列表的value中保存了很多信息,下面是peopleList組件的同步時(shí)候添加List數(shù)據(jù)代碼
          1 : this.owner.people_lb.addItem(this.data[ i ].name,{ id:i,sex:this.data[ i ].sex,name:this.data[ i ].name,ip:this.data[ i ].ip,cam:this.data[ i ].cam,mic:this.data[ i ].mic });
          這些用戶信息是通過(guò)共享對(duì)象存儲(chǔ)在服務(wù)器端的
          下面是服務(wù)器端people.asc文件中的相關(guān)實(shí)現(xiàn)
          1 : FCPeopleList.prototype.connect = function( client,userSex,cam,mic ) {
          2 : var cglobal = this.getClientGlobalStorage(client);
          3 : var clocal = this.getClientLocalStorage(client);
          4 : clocal.id = 'u' + this.getClientID(client);
          5 : userName=cglobal.username == null ? ' fc_lurker' : cglobal.username;
          6 : this.users_so.setProperty(clocal.id, { name:userName, cam:cam,mic:mic,sex:userSex,ip:client.ip });
          7 : }
          最后要做的就是點(diǎn)擊用戶列表中的名稱后顯示相應(yīng)的視頻了
          在onchange事件中寫入下面代碼就可以了:
          1 : //av2_mc 是右邊窗口的實(shí)例名稱
          2 : av2_mc.username_txt.text = this.getValue().name;
          3 : av2_mc.selectUserId = userID[this.getValue().name];
          4 : av2_mc.startReceive(userID[this.getValue().name]);
          以上簡(jiǎn)要說(shuō)明了基于FlashCom組件實(shí)現(xiàn)私聊的方法,分析的不是很周全,難免存在些Bug~只是作些交流,本人也會(huì)不斷完善
          posted on 2006-06-30 17:11 blog搬家了--[www.ialway.com/blog] 閱讀(1386) 評(píng)論(2)  編輯  收藏 所屬分類: FMS

          FeedBack:
          # re: 【轉(zhuǎn)帖】實(shí)現(xiàn)了視頻私聊功能  2009-02-13 05:56 123
          # re: 【轉(zhuǎn)帖】實(shí)現(xiàn)了視頻私聊功能  2009-10-22 14:36 fdsfdsf
          主站蜘蛛池模板: 汉源县| 黔东| 门头沟区| 巴青县| 太仓市| 建宁县| 黔西| 犍为县| 西华县| 建昌县| 灌阳县| 历史| 陈巴尔虎旗| 东丽区| 高唐县| 晴隆县| 城固县| 宁蒗| 石家庄市| 晋城| 南木林县| 文山县| 唐河县| 辉县市| 东台市| 九龙城区| 仁寿县| 乐山市| 天台县| 平顺县| 陆丰市| 盱眙县| 定边县| 福建省| 牟定县| 精河县| 桐城市| 颍上县| 平南县| 乐业县| 开江县|