第一次提交
This commit is contained in:
commit
8121362a03
4412 files changed
+1091845
No files matched your search
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,18 @@
|
||||
package com.yy.vip.pk.video.event
|
||||
{
|
||||
import flash.events.Event;
|
||||
|
||||
public class MasterSpeakEvent extends Event
|
||||
{
|
||||
|
||||
public static var MASTER_SPEAKING_CHANGED:String = "MASTER_SPEAKING_CHANGED";
|
||||
public var uid:uint;
|
||||
public var speaking:Boolean;
|
||||
public function MasterSpeakEvent(type:String, uid:uint, speaking:Boolean, bubbles:Boolean=false, cancelable:Boolean=false)
|
||||
{
|
||||
super(type, bubbles, cancelable);
|
||||
this.uid = uid;
|
||||
this.speaking = speaking;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.yy.vip.pk.video.event
|
||||
{
|
||||
import flash.events.Event;
|
||||
|
||||
public class PKVideoEvent extends Event
|
||||
{
|
||||
public static var VIDEO_REMOVED:String = "VIDEO_REMOVED";
|
||||
|
||||
public static var VIDEO_RESIZED:String = "VIDEO_RESIZED";
|
||||
|
||||
public static var VIDEO_ADDED:String = "VIDEO_ADDED";
|
||||
|
||||
public var data:Object;
|
||||
|
||||
public function PKVideoEvent(type:String, bubbles:Boolean=false, cancelable:Boolean=false)
|
||||
{
|
||||
super(type, bubbles, cancelable);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,741 @@
|
||||
package com.yy.vip.pk.video.service
|
||||
{
|
||||
import com.yy.flash.flv.FlvEvent;
|
||||
import com.yy.flash.flv.FlvMsg;
|
||||
import com.yy.flash.flv.FlvPlayStatus;
|
||||
import com.yy.flash.flv.VideoTypeInfo;
|
||||
import com.yy.flash.flv.YYFLV;
|
||||
import com.yy.flash.flv.utils.YYHashMap;
|
||||
import com.yy.vip.pk.base.components.MyAlert;
|
||||
import com.yy.vip.pk.event.CommonEvent;
|
||||
import com.yy.vip.pk.inter.IAppService;
|
||||
import com.yy.vip.pk.service.BaseService;
|
||||
import com.yy.vip.pk.service.DataReportService;
|
||||
import com.yy.vip.pk.util.JSONUtil;
|
||||
import com.yy.vip.pk.util.Tracer;
|
||||
import com.yy.vip.pk.video.event.MasterSpeakEvent;
|
||||
import com.yy.vip.pk.video.event.PKVideoEvent;
|
||||
import com.yy.vip.pk.video.util.ConfigVideo;
|
||||
|
||||
import flash.events.Event;
|
||||
import flash.events.EventDispatcher;
|
||||
import flash.events.TimerEvent;
|
||||
import flash.geom.Point;
|
||||
import flash.media.Video;
|
||||
import flash.utils.Timer;
|
||||
import flash.utils.clearInterval;
|
||||
import flash.utils.clearTimeout;
|
||||
import flash.utils.getTimer;
|
||||
import flash.utils.setInterval;
|
||||
import flash.utils.setTimeout;
|
||||
|
||||
import yy.YY;
|
||||
import yy.events.AudioEvent;
|
||||
import yy.events.ChannelEvent;
|
||||
import yy.events.ChannelMicListEvent;
|
||||
import yy.events.VideoEvent;
|
||||
|
||||
public class VideoServiceLeftSinglePK extends EventDispatcher
|
||||
{
|
||||
private static var _APP_SERVICE:IAppService;
|
||||
private var flv:YYFLV = null;
|
||||
private var clientModeVideos:YYHashMap = new YYHashMap();
|
||||
private var miniyyModeVideos:YYHashMap = new YYHashMap();
|
||||
private var sid:uint = 80000;
|
||||
private var subsid:uint = 2261570816;
|
||||
private var appid:uint = 0; //15013=娱乐 10057=虎牙
|
||||
private var sceneId:uint = 600; //100=娱乐首页 101=娱乐直播间 200=虎牙首页 201=虎牙直播间 300=财经首页 301=财经直播间 400=精彩世界 500=环球教育 600=vippk
|
||||
private static var _instance:VideoServiceLeftSinglePK;
|
||||
private var isPublish:Boolean;
|
||||
|
||||
public static function set APP_SERVICE(value:IAppService):void
|
||||
{
|
||||
_APP_SERVICE = value;
|
||||
|
||||
}
|
||||
|
||||
public static function getInstance():VideoServiceLeftSinglePK{
|
||||
if(!_instance)
|
||||
_instance = new VideoServiceLeftSinglePK();
|
||||
|
||||
return _instance;
|
||||
}
|
||||
/*[15:51:13:50] FlvLog.setFlvConfig appid=0 key=2 val=2000
|
||||
[15:51:13:50] FlvLog.setFlvConfig appid=0 key=3 val=1200
|
||||
[15:51:13:50] FlvLog.setFlvConfig appid=0 key=10 val=1300
|
||||
[15:51:13:50] FlvLog.setFlvConfig appid=0 key=4 val=800
|
||||
[15:51:13:50] FlvLog.setFlvConfig appid=0 key=11 val=16800
|
||||
[15:51:13:51] FlvLog.setFlvConfig appid=0 key=9 val=2000*/
|
||||
public function VideoServiceLeftSinglePK(){
|
||||
trace("palyModeVideo : " + String(BaseService.getInstance().configXML.palyModeVideo))
|
||||
if(BaseService.getInstance().configXML.palyModeVideo == undefined || String(BaseService.getInstance().configXML.palyModeVideo) == "0")
|
||||
{
|
||||
_playMode = CLIENT_MODE;
|
||||
}
|
||||
else if(BaseService.getInstance().configXML.palyModeVideo && String(BaseService.getInstance().configXML.palyModeVideo) == "1"){
|
||||
_playMode = WEB_MODE;
|
||||
}
|
||||
|
||||
YY.instance.video.lock();
|
||||
stopPublishTcp();
|
||||
YY.instance.video.addEventListener(VideoEvent.PUBLISH_STATUS,publishStatusHandler);
|
||||
YY.instance.video.addEventListener(VideoEvent.SUBSCRIBE_STATUS,subscribeStatusHandler);
|
||||
YY.instance.video.addEventListener(VideoEvent.CAMERA_STATUS,cameraStatusHandler);
|
||||
YY.instance.audio.addEventListener(AudioEvent.AUDIO_LISTEN_VOLUME_CHANGED,volumeChangeHandler);
|
||||
YY.instance.audio.addEventListener(AudioEvent.AUDIO_SPEAKER_STATUE_CHANGED,muteChangeHandler);
|
||||
YY.instance.channel.micList.addEventListener(ChannelMicListEvent.CLEAR,clearMicHandler);
|
||||
YY.instance.channel.micList.addEventListener(ChannelMicListEvent.USER_LEAVE,userLeaveMic);
|
||||
YY.instance.channel.addEventListener(ChannelEvent.USER_LEAVE_CHANNEL,levelChanleHandler);
|
||||
YY.instance.channel.micList.addEventListener(ChannelMicListEvent.SPEAKING_STATE_CHANGED,masterChangeMic);
|
||||
|
||||
if(!hasRegist && playMode == WEB_MODE)
|
||||
{
|
||||
hasRegist = true;
|
||||
soundInit();
|
||||
}
|
||||
|
||||
this.startYY(BaseService.getInstance().channelInfo.longId,BaseService.getInstance().subChannelInfo.longId,BaseService.APP_ID);
|
||||
}
|
||||
|
||||
|
||||
private function soundInit():void
|
||||
{
|
||||
if(flv)
|
||||
{
|
||||
YY.instance.audio.RegisterAudioController(BaseService.APP_ID);
|
||||
clearInterval(_registerIt);
|
||||
_registerIt =setInterval(function handler():void{
|
||||
if(playMode == WEB_MODE)
|
||||
YY.instance.audio.RegisterAudioController(BaseService.APP_ID);
|
||||
},5000);
|
||||
|
||||
var isturnonVolume:* = YY.instance.audio.isListenTurnOn().isturnon;
|
||||
var volume :Number = YY.instance.audio.getListenVolume().volume * 100;
|
||||
if(!isNaN(volume))
|
||||
flv.adjustVolume(volume);
|
||||
if(!isNaN(isturnonVolume) && isturnonVolume == false)
|
||||
flv.adjustVolume(0);
|
||||
}
|
||||
}
|
||||
|
||||
private function userLeaveMic(event:ChannelMicListEvent):void
|
||||
{
|
||||
if(event.eventData.uid == BaseService.getInstance().getCurrentUserInfo().uid){
|
||||
Tracer.debugLog("停止发布视频");
|
||||
stopPublishTcp();
|
||||
}
|
||||
else
|
||||
{
|
||||
stopSubscribeVideo(event.eventData.uid);
|
||||
}
|
||||
|
||||
}
|
||||
/**
|
||||
* 有用户leave
|
||||
**/
|
||||
private function levelChanleHandler(event:ChannelEvent):void
|
||||
{
|
||||
|
||||
if(event.eventData.uid == BaseService.getInstance().getCurrentUserInfo().uid){
|
||||
Tracer.debugLog("停止发布视频");
|
||||
stopPublishTcp();
|
||||
}
|
||||
else{
|
||||
this.stopSubscribeVideo(event.eventData.uid);
|
||||
}
|
||||
}
|
||||
|
||||
private function clearMicHandler(event:ChannelMicListEvent):void
|
||||
{
|
||||
Tracer.debugLog("清理麦序",Tracer.CLIENT_ACT_LOG);
|
||||
stopPublishTcp();
|
||||
closeAllVideos();
|
||||
|
||||
}
|
||||
|
||||
protected function onFlvLog(event:FlvEvent):void
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private function muteChangeHandler(event:AudioEvent):void
|
||||
{
|
||||
if(!flv){
|
||||
return;
|
||||
}
|
||||
if( playMode == WEB_MODE){
|
||||
var mute:*;
|
||||
if(event.eventData is String)
|
||||
mute = JSONUtil.decode(event.eventData.toString()).mute;
|
||||
else
|
||||
mute = event.eventData.mute;
|
||||
|
||||
if(!isNaN(mute) && mute == true){
|
||||
flv.adjustVolume(0);
|
||||
}
|
||||
else
|
||||
{
|
||||
var volume :Number = YY.instance.audio.getListenVolume().volume * 100;
|
||||
if(!isNaN(volume))
|
||||
flv.adjustVolume(volume)
|
||||
else
|
||||
flv.adjustVolume(100)
|
||||
}
|
||||
|
||||
flv.removeMuteUid(BaseService.getInstance().getCurrentUserInfo().uid);
|
||||
flv.addMuteUid(BaseService.getInstance().getCurrentUserInfo().uid);
|
||||
}
|
||||
}
|
||||
|
||||
private function volumeChangeHandler(event:AudioEvent):void
|
||||
{
|
||||
if(!flv){
|
||||
return
|
||||
}
|
||||
if( playMode == WEB_MODE){
|
||||
var volume:Number = 1;
|
||||
if(event.eventData is String)
|
||||
volume = (JSONUtil.decode(event.eventData.toString())).volume * 100 ;
|
||||
else
|
||||
volume = event.eventData.volume;
|
||||
|
||||
if(!isNaN(volume))
|
||||
flv.adjustVolume(volume)
|
||||
else
|
||||
flv.adjustVolume(100)
|
||||
|
||||
flv.removeMuteUid(BaseService.getInstance().getCurrentUserInfo().uid);
|
||||
flv.addMuteUid(BaseService.getInstance().getCurrentUserInfo().uid);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function startYY(sid:uint,subsid:uint,appid:uint):void{
|
||||
|
||||
this.sid = sid;
|
||||
this.subsid = subsid;
|
||||
this.appid = this.appid;
|
||||
|
||||
if(playMode == WEB_MODE){
|
||||
if(flv)
|
||||
flv.stopYY();
|
||||
startMiniYY();
|
||||
soundInit();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function onPlayVideo(event:FlvEvent):void {
|
||||
var uid:uint = event.data.uid;
|
||||
var v:Video = event.data.video;
|
||||
Tracer.debugLog('onPlayVideo uid=' + uid,Tracer.CLIENT_ACT_LOG);
|
||||
miniyyModeVideos.put(uid, v);
|
||||
var e : PKVideoEvent;
|
||||
if(uid != BaseService.getInstance().getCurrentUserInfo().uid)
|
||||
{
|
||||
closeSubscribeClienModeVideo(uid);
|
||||
e = new PKVideoEvent(PKVideoEvent.VIDEO_ADDED);
|
||||
e.data = {video:v,uid:uid};
|
||||
dispatchEvent(e);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
flv.removeMuteUid(BaseService.getInstance().getCurrentUserInfo().uid);
|
||||
flv.addMuteUid(BaseService.getInstance().getCurrentUserInfo().uid);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected function soundTimeOutHandler(event:TimerEvent):void
|
||||
{
|
||||
|
||||
if(playMode == CLIENT_MODE)
|
||||
return;
|
||||
this.changeClientMode();
|
||||
}
|
||||
|
||||
public function onPlayStatus(event:FlvEvent):void {
|
||||
var uid:uint = event.data.uid;
|
||||
var status:uint = event.data.status;
|
||||
var v:* = event.data.video;
|
||||
Tracer.debugLog('onPlayStatus uid=' + uid + ' status=' + FlvPlayStatus.getStatusStr(status),Tracer.CLIENT_ACT_LOG);
|
||||
if(uid == BaseService.getInstance().getCurrentUserInfo().uid){
|
||||
flv.removeMuteUid(BaseService.getInstance().getCurrentUserInfo().uid);
|
||||
flv.addMuteUid(BaseService.getInstance().getCurrentUserInfo().uid);
|
||||
}
|
||||
var e:PKVideoEvent;
|
||||
switch (status) {
|
||||
case FlvPlayStatus.FLV_STATUS_STOP:
|
||||
v = miniyyModeVideos.get(uid);
|
||||
if(uid != BaseService.getInstance().getCurrentUserInfo().uid)
|
||||
{
|
||||
e = new PKVideoEvent(PKVideoEvent.VIDEO_REMOVED);
|
||||
e.data = {video:v,uid:uid};
|
||||
dispatchEvent(e);
|
||||
miniyyModeVideos.remove(uid);
|
||||
stopSubscribeVideo(uid);
|
||||
}
|
||||
|
||||
break;
|
||||
case FlvPlayStatus.FLV_STATUS_VIDEO_RESOLUTION_CHANGED:
|
||||
|
||||
v = miniyyModeVideos.get(uid);
|
||||
e = new PKVideoEvent(PKVideoEvent.VIDEO_RESIZED);
|
||||
e.data = {video:v,uid:uid};
|
||||
dispatchEvent(e);
|
||||
|
||||
if(uid != BaseService.getInstance().getCurrentUserInfo().uid)
|
||||
{
|
||||
|
||||
e = new PKVideoEvent(PKVideoEvent.VIDEO_ADDED);
|
||||
e.data = {video:v,uid:uid};
|
||||
dispatchEvent(e);
|
||||
}
|
||||
break;
|
||||
case FlvPlayStatus.FLV_STATUS_PLAYING:
|
||||
if(uid != BaseService.getInstance().getCurrentUserInfo().uid)
|
||||
{
|
||||
if(v)
|
||||
miniyyModeVideos.put(uid,v);
|
||||
|
||||
v = miniyyModeVideos.get(uid);
|
||||
e = new PKVideoEvent(PKVideoEvent.VIDEO_ADDED);
|
||||
e.data = {video:v,uid:uid};
|
||||
dispatchEvent(e);
|
||||
}
|
||||
break;
|
||||
case FlvPlayStatus.AUDIO_STATUS_START:
|
||||
|
||||
break;
|
||||
case FlvPlayStatus.AUDIO_STATUS_STOP:
|
||||
|
||||
break;
|
||||
case FlvPlayStatus.AUDIO_VIDEO_OUT_OF_SYNC:
|
||||
this.changeClientMode();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private function closeSubscribeClienModeVideo(uid:uint):void
|
||||
{
|
||||
YY.instance.video.stopSubscribeVideo(uid);
|
||||
clientModeVideos.remove(uid);
|
||||
clearTimeout(_tryItMap[uid]);
|
||||
var event : PKVideoEvent = new PKVideoEvent(PKVideoEvent.VIDEO_REMOVED);
|
||||
event.data = {video:null,uid:uid};
|
||||
dispatchEvent(event);
|
||||
}
|
||||
|
||||
public function onMessage(msg:FlvMsg):void {
|
||||
trace("onMessage type=" + msg.getType() + " msg=" + msg.getMsg());
|
||||
}
|
||||
|
||||
public function flvLog(str:String):void {
|
||||
}
|
||||
|
||||
public function onNotifyMultiVideo(e:FlvEvent):void {
|
||||
trace("onNotifyMultiVideo");
|
||||
var needPlay:Boolean = e.data.needPlay;
|
||||
var appId:uint = e.data.appId;
|
||||
var videoTypeInfos:Vector.<VideoTypeInfo> = e.data.videoTypeInfos;
|
||||
if (needPlay){
|
||||
var channelId:uint = appId;
|
||||
var str:Array = [];
|
||||
var maxCodeRate:uint = 0;
|
||||
var maxCodeRateId:uint = 0;
|
||||
for each(var vt:VideoTypeInfo in videoTypeInfos){
|
||||
str.push(vt.channelId + '-' + vt.codeRate);
|
||||
if (vt.codeRate > maxCodeRate) {
|
||||
maxCodeRate = vt.codeRate;
|
||||
maxCodeRateId = vt.channelId;
|
||||
}
|
||||
|
||||
if (vt.channelType === 0) {
|
||||
maxCodeRateId = vt.channelId;
|
||||
break;
|
||||
}
|
||||
}
|
||||
flv.playChannel(maxCodeRateId);
|
||||
}
|
||||
}
|
||||
|
||||
public function onAudioSample(sample:Number):void {
|
||||
}
|
||||
|
||||
public function onAnchorStop(uid:uint):void{
|
||||
trace('onAnchorStop uid=' + uid);
|
||||
}
|
||||
|
||||
public function onAudioPlaySample(uid:uint, sample:Number):void {
|
||||
}
|
||||
|
||||
public function publishTcp(uid:uint):Object
|
||||
{
|
||||
|
||||
this.changeClientMode();
|
||||
ConfigVideo.setPublishVideo_480x360_Tcp();
|
||||
////ConfigVideo.setPublishVideo_320x240_Tcp();
|
||||
ConfigVideo.configEncode();
|
||||
|
||||
stopPublishTcp();
|
||||
|
||||
//var cameraList :Object = YY.instance.video.getCameraList();
|
||||
//var _camera :Object = YY.instance.video.getCurrentCamera();
|
||||
|
||||
var _cameraIndex:int = 0;
|
||||
|
||||
//if(_camera.ret == 0)
|
||||
//_cameraIndex = _camera.camera;
|
||||
|
||||
var point:Point = new Point(0,0);
|
||||
var res:Object = YY.instance.video.startPublishVideoTcpTransfer(point.x,point.y,ORGIN_VIDEO_WIDTH,ORGIN_VIDEO_HEIGHT,_cameraIndex,USE_FLV,true);
|
||||
Tracer.debugLog("uid:" + uid + ",开始发布视频,ret:"+res.ret,Tracer.ERROR_LOG,true);
|
||||
if(!res)
|
||||
res = {ret:50001};
|
||||
|
||||
if(res && Number(res.ret) == 45061)
|
||||
{
|
||||
_cameraIndex++;
|
||||
for(var i:uint = 0;i<3;i++)
|
||||
{
|
||||
res = YY.instance.video.startPublishVideoTcpTransfer(point.x,point.y,ORGIN_VIDEO_WIDTH,ORGIN_VIDEO_HEIGHT,_cameraIndex,USE_FLV,true);
|
||||
if(res && Number(res.ret) != 45061){
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(res && Number(res.ret) == 45061)
|
||||
{
|
||||
Tracer.debugLog("摄像头不可用哦!请打开视频设置下呗",Tracer.CLIENT_ACT_LOG)
|
||||
MyAlert.show("摄像头不可用哦!请打开视频设置下呗");
|
||||
YY.instance.video.stopPublish();
|
||||
res.ret = 45062;
|
||||
return res;
|
||||
|
||||
}
|
||||
if(res && Number(res.ret) == 984832)
|
||||
{
|
||||
Tracer.debugLog("发布视频api既然超时了,重试下呗",Tracer.CLIENT_ACT_LOG);
|
||||
YY.instance.video.stopPublish();
|
||||
res.ret = 984832;
|
||||
}
|
||||
|
||||
if(res && Number(res.ret) == 0)
|
||||
{
|
||||
isPublish = true;
|
||||
clientModeVideos.put(BaseService.getInstance().getCurrentUserInfo().uid,res.video);
|
||||
var e :PKVideoEvent= new PKVideoEvent(PKVideoEvent.VIDEO_ADDED);
|
||||
e.data = {video:res.video,uid:BaseService.getInstance().getCurrentUserInfo().uid};
|
||||
dispatchEvent(e);
|
||||
this.startPublishTime = new Date().time;
|
||||
clearTimeout(this.startPublishTimeIt);
|
||||
this.startPublishTimeIt = setTimeout(function handler():void{
|
||||
clearTimeout(startPublishTimeIt);
|
||||
startPublishTime = new Date().time;
|
||||
dataReport();
|
||||
},10 * 1000 * 60);
|
||||
}
|
||||
else
|
||||
{
|
||||
Tracer.debugLog("uid:" + uid + ",操作失败,请检查设备或重进频道再试:" + res.ret,Tracer.ERROR_LOG,true);
|
||||
MyAlert.show("操作失败,请检查设备或重进频道再试 :" + res.ret);
|
||||
isPublish = false;
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
public function stopPublishTcp():void
|
||||
{
|
||||
if(!isPublish)
|
||||
return;
|
||||
var res :Object = YY.instance.video.stopPublish();
|
||||
Tracer.debugLog("调用停止发布视频返回结果:"+res.ret,Tracer.CLIENT_ACT_LOG);
|
||||
clientModeVideos.remove(BaseService.getInstance().getCurrentUserInfo().uid);
|
||||
isPublish = false;
|
||||
var endPublishTime :Number = new Date().time;
|
||||
clearTimeout(this.startPublishTimeIt);
|
||||
if((endPublishTime - this.startPublishTime)/1000/60 >= 10)
|
||||
{
|
||||
dataReport();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private function publishStatusHandler(event:VideoEvent):void
|
||||
{
|
||||
if(event.eventData.status !=0)
|
||||
{
|
||||
dispatchEvent(new CommonEvent(CommonEvent.PUBLISH_FAIL));
|
||||
Tracer.debugLog("发布视频失败:" + event.eventData.status,Tracer.ERROR_LOG);
|
||||
MyAlert.show("发布视频失败,请重进频道再试" );
|
||||
isPublish = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
Tracer.debugLog("发布视频成功:" + event.eventData.status,Tracer.ERROR_LOG);
|
||||
|
||||
}
|
||||
}
|
||||
private var cit:int;
|
||||
private var chestKeyMarInt:uint;
|
||||
private var hasRegist:Boolean;
|
||||
|
||||
private function cameraStatusHandler(event:VideoEvent):void
|
||||
{
|
||||
clearTimeout(cit);
|
||||
cit = setTimeout(function dd():void{
|
||||
clearTimeout(cit);
|
||||
|
||||
if(event.eventData.status == 1)
|
||||
{
|
||||
MyAlert.show("摄像头给占用了哦!请打开视频设置下呗");
|
||||
|
||||
}
|
||||
else if(event.eventData.status == 2)
|
||||
{
|
||||
MyAlert.show("您的摄像头暂不能支持哦!请打开视频设置下呗");
|
||||
|
||||
}
|
||||
Tracer.debugLog("摄像头状态:" + event.eventData.status,Tracer.CLIENT_ACT_LOG);
|
||||
var e:CommonEvent = new CommonEvent(CommonEvent.CAMERA_STATUS);
|
||||
dispatchEvent(e);
|
||||
|
||||
},3000);
|
||||
}
|
||||
private function startStartSubscribeVideoTcpTransfer(uid:uint):void{
|
||||
if(uid == 0)
|
||||
return;
|
||||
closeSubscribeClienModeVideo(uid);
|
||||
var res :Object = YY.instance.video.startSubscribeVideoTcpTransfer(0,0,ORGIN_VIDEO_WIDTH,ORGIN_VIDEO_HEIGHT,uid,USE_FLV,true);
|
||||
if(res.ret == 0)
|
||||
{
|
||||
clientModeVideos.put(uid, res.video);
|
||||
var event2 :PKVideoEvent= new PKVideoEvent(PKVideoEvent.VIDEO_ADDED);
|
||||
event2.data = {video:res.video,uid:uid};
|
||||
dispatchEvent(event2);
|
||||
clearTimeout(_tryItMap[uid]);
|
||||
}
|
||||
else
|
||||
{
|
||||
_tryItMap[uid] = setTimeout(function handler(...params):void{
|
||||
clearTimeout(_tryItMap[params[0]]);
|
||||
startStartSubscribeVideoTcpTransfer(params[0]);
|
||||
},4000,uid);
|
||||
}
|
||||
}
|
||||
private var _tryItMap: Object = {};
|
||||
private function subscribeStatusHandler(event:VideoEvent):void
|
||||
{
|
||||
Tracer.debugLog("主播上下视频通知,uid:"+event.eventData.uid + ",status:"+event.eventData.status,Tracer.CLIENT_ACT_LOG);
|
||||
var e:CommonEvent = new CommonEvent(CommonEvent.SUBSCRIBE_CHANGE);
|
||||
e.data = event.eventData;
|
||||
dispatchEvent(e);
|
||||
if(playMode == CLIENT_MODE)
|
||||
{
|
||||
if(event.eventData.status == 0)
|
||||
{
|
||||
checkVideo(event.eventData.uid);
|
||||
}
|
||||
else
|
||||
{
|
||||
closeSubscribeClienModeVideo(event.eventData.uid);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function checkVideo(uid:uint):void{
|
||||
|
||||
var event : PKVideoEvent;
|
||||
if(uid != BaseService.getInstance().getCurrentUserInfo().uid)
|
||||
{
|
||||
var miniYYFLag :Boolean = false;
|
||||
if(miniyyModeVideos.getValue(uid))//有效
|
||||
{
|
||||
miniYYFLag = true;
|
||||
closeSubscribeClienModeVideo(uid);
|
||||
event = new PKVideoEvent(PKVideoEvent.VIDEO_ADDED);
|
||||
event.data = {video:miniyyModeVideos.getValue(uid),uid:uid};
|
||||
dispatchEvent(event);
|
||||
}
|
||||
else if(clientModeVideos.getValue(uid))//有效
|
||||
{
|
||||
event = new PKVideoEvent(PKVideoEvent.VIDEO_ADDED);
|
||||
event.data = {video:clientModeVideos.getValue(uid),uid:uid};
|
||||
dispatchEvent(event);
|
||||
}
|
||||
else
|
||||
{
|
||||
if(playMode == CLIENT_MODE)
|
||||
startStartSubscribeVideoTcpTransfer(uid);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public static var CHANGE_PLAY_MODE_EVENT :String = "CHANGE_PLAY_MODE_EVENT";
|
||||
public static var WEB_MODE :uint = 0;
|
||||
public static var CLIENT_MODE :uint = 1;
|
||||
private var _playMode:int = CLIENT_MODE;
|
||||
private var _registerIt:uint;
|
||||
public static var ORGIN_VIDEO_WIDTH:int = 320;
|
||||
public static var ORGIN_VIDEO_HEIGHT:int = 240;
|
||||
private var USE_FLV:Boolean = false;
|
||||
private var _muteIt:uint;
|
||||
public function changeClientMode():void{
|
||||
if(playMode == CLIENT_MODE)
|
||||
return;
|
||||
playMode = CLIENT_MODE;
|
||||
clearInterval(_registerIt);
|
||||
clearInterval(_muteIt);
|
||||
|
||||
if(flv)
|
||||
flv.stopYY();
|
||||
closeAllVideos();
|
||||
|
||||
YY.instance.audio.UnregisterAudioController(BaseService.APP_ID);
|
||||
var event :Event = new Event(CHANGE_PLAY_MODE_EVENT);
|
||||
dispatchEvent(event)
|
||||
}
|
||||
public function changeWebMode():void{
|
||||
if(playMode == WEB_MODE)
|
||||
return;
|
||||
playMode = WEB_MODE;
|
||||
closeAllVideos();
|
||||
startMiniYY();
|
||||
|
||||
soundInit();
|
||||
var event:Event = new Event(CHANGE_PLAY_MODE_EVENT);
|
||||
dispatchEvent(event);
|
||||
|
||||
}
|
||||
|
||||
private function startMiniYY():void
|
||||
{
|
||||
if(!flv)
|
||||
{
|
||||
flv = new YYFLV();
|
||||
flv.setFlvConfig(0, 2, 2000);
|
||||
flv.setFlvConfig(0, 4, 800);
|
||||
flv.setFlvConfig(0, 11, 16800);
|
||||
flv.setFlvConfig(0, 13, 30);
|
||||
flv.setFlvConfig(0, 14, 2);
|
||||
flv.addEventListener(FlvEvent.PLAY_STATUS, onPlayStatus);
|
||||
flv.addEventListener(FlvEvent.PLAY_VIDEO, onPlayVideo);
|
||||
flv.addEventListener(FlvEvent.MULTI_VIDEOS, onNotifyMultiVideo);
|
||||
flv.addEventListener(FlvEvent.FLV_LOG,onFlvLog);
|
||||
flv.setLogMode(2);
|
||||
}
|
||||
|
||||
flv.startYY(this.sid, this.subsid, this.appid, this.sceneId,BaseService.getInstance().getCurrentUserInfo().uid);
|
||||
flv.removeMuteUid(BaseService.getInstance().getCurrentUserInfo().uid);
|
||||
flv.addMuteUid(BaseService.getInstance().getCurrentUserInfo().uid);
|
||||
|
||||
clearInterval(_muteIt);
|
||||
_muteIt = setInterval(function handler():void{
|
||||
flv.removeMuteUid(BaseService.getInstance().getCurrentUserInfo().uid);
|
||||
flv.addMuteUid(BaseService.getInstance().getCurrentUserInfo().uid);
|
||||
},3000);
|
||||
}
|
||||
|
||||
|
||||
public function stopSubscribeVideo(uid:uint):void{
|
||||
if(uid == BaseService.getInstance().getCurrentUserInfo().uid)
|
||||
return;
|
||||
|
||||
clearTimeout(_tryItMap[uid]);
|
||||
YY.instance.video.stopSubscribeVideo(uid);
|
||||
var event : PKVideoEvent = new PKVideoEvent(PKVideoEvent.VIDEO_REMOVED);
|
||||
event.data = {video:null,uid:uid};
|
||||
dispatchEvent(event);
|
||||
if(miniyyModeVideos.containsKey(uid) || clientModeVideos.containsKey(uid))
|
||||
Tracer.debugLog("停止订阅视频:" + uid,Tracer.CLIENT_ACT_LOG);
|
||||
miniyyModeVideos.remove(uid);
|
||||
clientModeVideos.remove(uid);
|
||||
}
|
||||
private function closeAllVideos():void
|
||||
{
|
||||
var uid:uint;
|
||||
var video:*;
|
||||
for each(uid in clientModeVideos.keys()){
|
||||
video = clientModeVideos.get(uid);
|
||||
stopSubscribeVideo(uid);
|
||||
}
|
||||
for each(uid in miniyyModeVideos.keys()){
|
||||
video = miniyyModeVideos.get(uid);
|
||||
stopSubscribeVideo(uid);
|
||||
}
|
||||
miniyyModeVideos.clear();
|
||||
clientModeVideos.clear();
|
||||
}
|
||||
|
||||
public function get playMode():int{
|
||||
return BaseService.getInstance().isWebYY ?CLIENT_MODE:_playMode;
|
||||
}
|
||||
public function set playMode(value:int):void{
|
||||
this._playMode = value;
|
||||
}
|
||||
private var _oldPlayMode:uint;
|
||||
private var _isCloseAllVideoTra:Boolean = false;
|
||||
private var startPublishTime:Number;
|
||||
private var startPublishTimeIt:uint;
|
||||
public function closeAllVideoTra():void{
|
||||
clearInterval(_registerIt);
|
||||
clearInterval(_muteIt);
|
||||
if(flv)
|
||||
flv.stopYY();
|
||||
closeAllVideos();
|
||||
_oldPlayMode = _playMode;
|
||||
_isCloseAllVideoTra =true;
|
||||
_playMode = -1;
|
||||
YY.instance.audio.UnregisterAudioController(BaseService.APP_ID);
|
||||
|
||||
}
|
||||
public function openAllVideoTra():void{
|
||||
if(_oldPlayMode == WEB_MODE)
|
||||
{
|
||||
changeWebMode();
|
||||
}
|
||||
else if(_oldPlayMode == CLIENT_MODE)
|
||||
{
|
||||
changeClientMode();
|
||||
}
|
||||
_isCloseAllVideoTra =false;
|
||||
}
|
||||
public function isCloseAllVideoTra():Boolean{
|
||||
return _isCloseAllVideoTra;
|
||||
}
|
||||
private function dataReport():void
|
||||
{
|
||||
DataReportService.getInstance().dataReport(BaseService.getInstance().getCurrentUserInfo().uid,DataReportService.DATA_TYPE_VIDEO_PUBLISH_TIME,"开播大于10分钟");
|
||||
}
|
||||
|
||||
public function getVideoByUid(uid:uint):Video{
|
||||
if(playMode == CLIENT_MODE)
|
||||
return clientModeVideos.get(uid);
|
||||
else if(playMode == WEB_MODE)
|
||||
return miniyyModeVideos.get(uid);
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 麦序音频变化
|
||||
* */
|
||||
private var _speakingDatas:Object = {};
|
||||
private function masterChangeMic(e:ChannelMicListEvent):void{
|
||||
_speakingDatas[e.eventData.uid] = e.eventData.speaking;
|
||||
var event:MasterSpeakEvent = new MasterSpeakEvent(MasterSpeakEvent.MASTER_SPEAKING_CHANGED,e.eventData.uid,e.eventData.speaking);
|
||||
dispatchEvent(event);
|
||||
}
|
||||
|
||||
public function getSpeakingData(_userId:uint):Object
|
||||
{
|
||||
return _speakingDatas[_userId];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,487 @@
|
||||
package com.yy.vip.pk.video.service
|
||||
{
|
||||
import com.yy.flash.flv.FlvEvent;
|
||||
import com.yy.flash.flv.FlvMsg;
|
||||
import com.yy.flash.flv.FlvPlayStatus;
|
||||
import com.yy.flash.flv.VideoTypeInfo;
|
||||
import com.yy.flash.flv.YYFLV;
|
||||
import com.yy.flash.flv.utils.YYHashMap;
|
||||
import com.yy.impl.IVideoSocket;
|
||||
import com.yy.vip.pk.base.components.MyAlert;
|
||||
import com.yy.vip.pk.event.CommonEvent;
|
||||
import com.yy.vip.pk.service.BaseService;
|
||||
import com.yy.vip.pk.util.JSONUtil;
|
||||
import com.yy.vip.pk.util.Tracer;
|
||||
import com.yy.vip.pk.video.event.PKVideoEvent;
|
||||
import com.yy.vip.pk.video.util.ConfigVideo;
|
||||
|
||||
import flash.events.Event;
|
||||
import flash.events.EventDispatcher;
|
||||
import flash.geom.Point;
|
||||
import flash.media.Video;
|
||||
import flash.utils.clearTimeout;
|
||||
import flash.utils.setInterval;
|
||||
import flash.utils.setTimeout;
|
||||
|
||||
import yy.YY;
|
||||
import yy.events.AudioEvent;
|
||||
import yy.events.ChannelEvent;
|
||||
import yy.events.ChannelMicListEvent;
|
||||
import yy.events.VideoEvent;
|
||||
|
||||
public class VideoServiceRightSinglePK extends EventDispatcher
|
||||
{
|
||||
private var flv:YYFLV = null;
|
||||
private var videos:YYHashMap = new YYHashMap();
|
||||
|
||||
private var sid:uint = 80000;
|
||||
private var subsid:uint = 2261570816;
|
||||
private var appid:uint = 0; //15013=娱乐 10057=虎牙
|
||||
private var sceneId:uint = 610; //100=娱乐首页 101=娱乐直播间 200=虎牙首页 201=虎牙直播间 300=财经首页 301=财经直播间 400=精彩世界 500=环球教育 600=vippk
|
||||
private static var _instance:VideoServiceRightSinglePK;
|
||||
protected var isPublish:Boolean;
|
||||
public static function getInstance():VideoServiceRightSinglePK{
|
||||
if(!_instance)
|
||||
_instance = new VideoServiceRightSinglePK();
|
||||
|
||||
return _instance;
|
||||
}
|
||||
|
||||
/*[15:51:13:50] FlvLog.setFlvConfig appid=0 key=2 val=2000
|
||||
[15:51:13:50] FlvLog.setFlvConfig appid=0 key=3 val=1200
|
||||
[15:51:13:50] FlvLog.setFlvConfig appid=0 key=10 val=1300
|
||||
[15:51:13:50] FlvLog.setFlvConfig appid=0 key=4 val=800
|
||||
[15:51:13:50] FlvLog.setFlvConfig appid=0 key=11 val=16800
|
||||
[15:51:13:51] FlvLog.setFlvConfig appid=0 key=9 val=2000*/
|
||||
public function VideoServiceRightSinglePK(){
|
||||
|
||||
stopPublishTcp();
|
||||
YY.instance.video.addEventListener(VideoEvent.PUBLISH_STATUS,publishStatusHandler);
|
||||
YY.instance.video.addEventListener(VideoEvent.SUBSCRIBE_STATUS,subscribeStatusHandler);
|
||||
YY.instance.video.addEventListener(VideoEvent.CAMERA_STATUS,cameraStatusHandler);
|
||||
//YY.instance.audio.addEventListener(AudioEvent.AUDIO_LISTEN_VOLUME_CHANGED,volumeChangeHandler);
|
||||
//YY.instance.audio.addEventListener(AudioEvent.AUDIO_SPEAKER_STATUE_CHANGED,muteChangeHandler);
|
||||
YY.instance.channel.micList.addEventListener(ChannelMicListEvent.CLEAR,clearMicHandler);
|
||||
YY.instance.channel.micList.addEventListener(ChannelMicListEvent.USER_LEAVE,userLeaveMic);
|
||||
YY.instance.channel.addEventListener(ChannelEvent.USER_LEAVE_CHANNEL,levelChanleHandler);
|
||||
|
||||
}
|
||||
|
||||
private function soundInit():void
|
||||
{
|
||||
if(flv)
|
||||
{
|
||||
var isturnonVolume:* = YY.instance.audio.isListenTurnOn().isturnon;
|
||||
var volume :Number = YY.instance.audio.getListenVolume().volume * 100;
|
||||
/*if(!isNaN(volume))
|
||||
flv.adjustVolume(volume);
|
||||
if(!isNaN(isturnonVolume) && isturnonVolume == false)*/
|
||||
flv.adjustVolume(0);
|
||||
}
|
||||
}
|
||||
|
||||
private function userLeaveMic(event:ChannelMicListEvent):void
|
||||
{
|
||||
if(event.eventData.uid == BaseService.getInstance().getCurrentUserInfo().uid){
|
||||
Tracer.debugLog("停止发布视频");
|
||||
YY.instance.video.stopPublish();
|
||||
}
|
||||
else
|
||||
{
|
||||
stopSubscribeVideo(event.eventData.uid);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 有用户leave
|
||||
**/
|
||||
private function levelChanleHandler(event:ChannelEvent):void
|
||||
{
|
||||
|
||||
if(event.eventData.uid == BaseService.getInstance().getCurrentUserInfo().uid){
|
||||
Tracer.debugLog("停止发布视频");
|
||||
YY.instance.video.stopPublish();
|
||||
}
|
||||
else{
|
||||
this.stopSubscribeVideo(event.eventData.uid);
|
||||
}
|
||||
}
|
||||
|
||||
private function clearMicHandler(event:ChannelMicListEvent):void
|
||||
{
|
||||
Tracer.debugLog("清理麦序",Tracer.CLIENT_ACT_LOG);
|
||||
YY.instance.video.stopPublish();
|
||||
closeAllVideos();
|
||||
}
|
||||
|
||||
protected function onFlvLog(event:FlvEvent):void
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private function muteChangeHandler(event:AudioEvent):void
|
||||
{
|
||||
if(!flv){
|
||||
return;
|
||||
}
|
||||
var mute:*;
|
||||
if(event.eventData is String)
|
||||
mute = JSONUtil.decode(event.eventData.toString()).mute;
|
||||
else
|
||||
mute = event.eventData.mute;
|
||||
|
||||
if(!isNaN(mute) && mute == true){
|
||||
flv.adjustVolume(0);
|
||||
}
|
||||
else
|
||||
{
|
||||
var volume :Number = YY.instance.audio.getListenVolume().volume * 100;
|
||||
if(!isNaN(volume))
|
||||
flv.adjustVolume(volume)
|
||||
else
|
||||
flv.adjustVolume(100)
|
||||
}
|
||||
|
||||
flv.removeMuteUid(BaseService.getInstance().getCurrentUserInfo().uid);
|
||||
flv.addMuteUid(BaseService.getInstance().getCurrentUserInfo().uid);
|
||||
|
||||
}
|
||||
|
||||
private function volumeChangeHandler(event:AudioEvent):void
|
||||
{
|
||||
if(!flv){
|
||||
return
|
||||
}
|
||||
var volume:Number = 1;
|
||||
if(event.eventData is String)
|
||||
volume = (JSONUtil.decode(event.eventData.toString())).volume * 100 ;
|
||||
else
|
||||
volume = event.eventData.volume;
|
||||
|
||||
if(!isNaN(volume))
|
||||
flv.adjustVolume(volume)
|
||||
else
|
||||
flv.adjustVolume(100)
|
||||
|
||||
flv.removeMuteUid(BaseService.getInstance().getCurrentUserInfo().uid);
|
||||
flv.addMuteUid(BaseService.getInstance().getCurrentUserInfo().uid);
|
||||
}
|
||||
|
||||
public function startYY(sid:uint,subsid:uint,appid:uint):void{
|
||||
|
||||
this.sid = sid;
|
||||
this.subsid = subsid;
|
||||
this.appid = this.appid;
|
||||
|
||||
if(flv)
|
||||
flv.stopYY();
|
||||
startMiniYY();
|
||||
soundInit();
|
||||
|
||||
}
|
||||
public function onPlayVideo(event:FlvEvent):void {
|
||||
var uid:uint = event.data.uid;
|
||||
var v:Video = event.data.video;
|
||||
Tracer.debugLog('onPlayVideo uid=' + uid,Tracer.CLIENT_ACT_LOG);
|
||||
|
||||
videos.put(uid, v);
|
||||
|
||||
if(uid != BaseService.getInstance().getCurrentUserInfo().uid)
|
||||
{
|
||||
var e : PKVideoEvent = new PKVideoEvent(PKVideoEvent.VIDEO_ADDED);
|
||||
e.data = {video:v,uid:uid};
|
||||
dispatchEvent(e);
|
||||
}
|
||||
else
|
||||
{
|
||||
flv.removeMuteUid(BaseService.getInstance().getCurrentUserInfo().uid);
|
||||
flv.addMuteUid(BaseService.getInstance().getCurrentUserInfo().uid);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function onPlayStatus(event:FlvEvent):void {
|
||||
var uid:uint = event.data.uid;
|
||||
var status:uint = event.data.status;
|
||||
var v:Video = event.data.video;
|
||||
Tracer.debugLog('onPlayStatus uid=' + uid + ' status=' + FlvPlayStatus.getStatusStr(status),Tracer.CLIENT_ACT_LOG);
|
||||
if(uid == BaseService.getInstance().getCurrentUserInfo().uid){
|
||||
flv.removeMuteUid(BaseService.getInstance().getCurrentUserInfo().uid);
|
||||
flv.addMuteUid(BaseService.getInstance().getCurrentUserInfo().uid);
|
||||
}
|
||||
var e:PKVideoEvent;
|
||||
switch (status) {
|
||||
case FlvPlayStatus.FLV_STATUS_STOP:
|
||||
v = videos.get(uid);
|
||||
if (v) {
|
||||
if(uid != BaseService.getInstance().getCurrentUserInfo().uid)
|
||||
{
|
||||
e = new PKVideoEvent(PKVideoEvent.VIDEO_REMOVED);
|
||||
e.data = {video:v,uid:uid};
|
||||
dispatchEvent(e);
|
||||
}
|
||||
videos.remove(uid);
|
||||
}
|
||||
break;
|
||||
case FlvPlayStatus.FLV_STATUS_VIDEO_RESOLUTION_CHANGED:
|
||||
v = videos.get(uid);
|
||||
e = new PKVideoEvent(PKVideoEvent.VIDEO_RESIZED);
|
||||
e.data = {video:v,uid:uid};
|
||||
dispatchEvent(e);
|
||||
|
||||
if(uid != BaseService.getInstance().getCurrentUserInfo().uid)
|
||||
{
|
||||
e = new PKVideoEvent(PKVideoEvent.VIDEO_ADDED);
|
||||
e.data = {video:v,uid:uid};
|
||||
dispatchEvent(e);
|
||||
}
|
||||
break;
|
||||
case FlvPlayStatus.FLV_STATUS_PLAYING:
|
||||
if(uid == BaseService.getInstance().getCurrentUserInfo().uid)
|
||||
return;
|
||||
if(v)
|
||||
videos.put(uid,v);
|
||||
|
||||
v = videos.get(uid);
|
||||
e = new PKVideoEvent(PKVideoEvent.VIDEO_ADDED);
|
||||
e.data = {video:v,uid:uid};
|
||||
dispatchEvent(e);
|
||||
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function onMessage(msg:FlvMsg):void {
|
||||
trace("onMessage type=" + msg.getType() + " msg=" + msg.getMsg());
|
||||
}
|
||||
|
||||
public function flvLog(str:String):void {
|
||||
}
|
||||
|
||||
public function onNotifyMultiVideo(e:FlvEvent):void {
|
||||
trace("onNotifyMultiVideo");
|
||||
var needPlay:Boolean = e.data.needPlay;
|
||||
var appId:uint = e.data.appId;
|
||||
var videoTypeInfos:Vector.<VideoTypeInfo> = e.data.videoTypeInfos;
|
||||
if (needPlay){
|
||||
var channelId:uint = appId;
|
||||
var str:Array = [];
|
||||
var maxCodeRate:uint = 0;
|
||||
var maxCodeRateId:uint = 0;
|
||||
for each(var vt:VideoTypeInfo in videoTypeInfos){
|
||||
str.push(vt.channelId + '-' + vt.codeRate);
|
||||
if (vt.codeRate > maxCodeRate) {
|
||||
maxCodeRate = vt.codeRate;
|
||||
maxCodeRateId = vt.channelId;
|
||||
}
|
||||
|
||||
if (vt.channelType === 0) {
|
||||
maxCodeRateId = vt.channelId;
|
||||
break;
|
||||
}
|
||||
}
|
||||
flv.playChannel(maxCodeRateId);
|
||||
}
|
||||
}
|
||||
|
||||
public function onAudioSample(sample:Number):void {
|
||||
}
|
||||
|
||||
public function onAnchorStop(uid:uint):void{
|
||||
trace('onAnchorStop uid=' + uid);
|
||||
}
|
||||
|
||||
public function onAudioPlaySample(uid:uint, sample:Number):void {
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function publishTcp(uid:uint):Object
|
||||
{
|
||||
ConfigVideo.configEncode();
|
||||
ConfigVideo.setPublishVideo_480x360_Tcp();
|
||||
|
||||
stopPublishTcp();
|
||||
var cameraList :Object = YY.instance.video.getCameraList();
|
||||
|
||||
Tracer.debugLog("摄像头res"+JSONUtil.encode(cameraList),Tracer.CLIENT_ACT_LOG);
|
||||
|
||||
var _cameraIndex:int = 0;
|
||||
|
||||
var point:Point = new Point(0,0);
|
||||
var res:Object = YY.instance.video.startPublishVideoTcpTransfer(point.x,point.y,ORGIN_VIDEO_WIDTH,ORGIN_VIDEO_HEIGHT,_cameraIndex,false,true);
|
||||
Tracer.debugLog("uid:" + uid + ",开始发布视频,ret:"+res.ret,Tracer.SYS_LOG,true);
|
||||
if(!res)
|
||||
res = {ret:50001};
|
||||
|
||||
if(res && res.ret == 45061)
|
||||
{
|
||||
_cameraIndex++;
|
||||
res = YY.instance.video.startPublishVideoTcpTransfer(point.x,point.y,ORGIN_VIDEO_WIDTH,ORGIN_VIDEO_HEIGHT,_cameraIndex,false,true);
|
||||
}
|
||||
|
||||
if(res && res.ret == 45061)
|
||||
{
|
||||
_cameraIndex++;
|
||||
res = YY.instance.video.startPublishVideoTcpTransfer(point.x,point.y,ORGIN_VIDEO_WIDTH,ORGIN_VIDEO_HEIGHT,_cameraIndex,false,true);
|
||||
}
|
||||
|
||||
if(res && res.ret == 45061)
|
||||
{
|
||||
_cameraIndex++;
|
||||
res = YY.instance.video.startPublishVideoTcpTransfer(point.x,point.y,ORGIN_VIDEO_WIDTH,ORGIN_VIDEO_HEIGHT,_cameraIndex,false,true);
|
||||
}
|
||||
Tracer.debugLog("摄像头index:"+_cameraIndex,Tracer.CLIENT_ACT_LOG);
|
||||
if(res && res.ret == 45061)
|
||||
{
|
||||
Tracer.debugLog("摄像头不可用哦!请打开视频设置下呗",Tracer.CLIENT_ACT_LOG)
|
||||
MyAlert.show("摄像头不可用哦!请打开视频设置下呗");
|
||||
|
||||
YY.instance.video.stopPublish();
|
||||
res.ret = 45062;
|
||||
return res;
|
||||
|
||||
}
|
||||
if(res && res.ret == 984832)
|
||||
{
|
||||
Tracer.debugLog("开始发布视频返回:api既然超时了",Tracer.CLIENT_ACT_LOG);
|
||||
YY.instance.video.stopPublish();
|
||||
res.ret = 984832;
|
||||
}
|
||||
|
||||
if(res && res.ret == 0)
|
||||
{
|
||||
isPublish = true;
|
||||
var e :PKVideoEvent= new PKVideoEvent(PKVideoEvent.VIDEO_ADDED);
|
||||
e.data = {video:res.video,uid:BaseService.getInstance().getCurrentUserInfo().uid};
|
||||
dispatchEvent(e);
|
||||
}
|
||||
else
|
||||
{
|
||||
MyAlert.show("发布视频失败,请重进频道再试");
|
||||
isPublish = false;
|
||||
}
|
||||
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
public function stopPublishTcp():void
|
||||
{
|
||||
YY.instance.video.stopPublish();
|
||||
isPublish = false;
|
||||
}
|
||||
|
||||
private function publishStatusHandler(event:VideoEvent):void
|
||||
{
|
||||
if(event.eventData.status !=0)
|
||||
{
|
||||
dispatchEvent(new CommonEvent(CommonEvent.PUBLISH_FAIL));
|
||||
Tracer.debugLog("发布视频失败:" + event.eventData.status,Tracer.ERROR_LOG);
|
||||
MyAlert.show("发布视频失败,请重进频道再试" );
|
||||
}
|
||||
else
|
||||
{
|
||||
Tracer.debugLog("发布视频成功:" + event.eventData.status,Tracer.ERROR_LOG);
|
||||
|
||||
}
|
||||
}
|
||||
private var cit:int;
|
||||
private var chestKeyMarInt:uint;
|
||||
private var hasRegist:Boolean;
|
||||
|
||||
private function cameraStatusHandler(event:VideoEvent):void
|
||||
{
|
||||
clearTimeout(cit);
|
||||
cit = setTimeout(function dd():void{
|
||||
clearTimeout(cit);
|
||||
|
||||
if(event.eventData.status == 1)
|
||||
{
|
||||
MyAlert.show("摄像头给占用了哦!请打开视频设置下呗");
|
||||
|
||||
}
|
||||
else if(event.eventData.status == 2)
|
||||
{
|
||||
MyAlert.show("您的摄像头暂不能支持哦!请重新换一个呗");
|
||||
|
||||
}
|
||||
Tracer.debugLog("摄像头状态:" + event.eventData.status,Tracer.CLIENT_ACT_LOG);
|
||||
var e:CommonEvent = new CommonEvent(CommonEvent.CAMERA_STATUS);
|
||||
dispatchEvent(e);
|
||||
|
||||
},3000);
|
||||
}
|
||||
|
||||
|
||||
private function subscribeStatusHandler(event:VideoEvent):void
|
||||
{
|
||||
Tracer.debugLog("主播上下视频通知,uid:"+event.eventData.uid + ",status:"+event.eventData.status,Tracer.CLIENT_ACT_LOG);
|
||||
var e:CommonEvent = new CommonEvent(CommonEvent.SUBSCRIBE_CHANGE);
|
||||
e.data = event.eventData;
|
||||
dispatchEvent(e);
|
||||
}
|
||||
|
||||
public function checkVideo(uid:uint):void{
|
||||
|
||||
|
||||
var event : PKVideoEvent;
|
||||
|
||||
if(uid != BaseService.getInstance().getCurrentUserInfo().uid)
|
||||
{
|
||||
if(videos.getValue(uid))
|
||||
{
|
||||
event = new PKVideoEvent(PKVideoEvent.VIDEO_ADDED);
|
||||
event.data = {video:videos.getValue(uid),uid:uid};
|
||||
dispatchEvent(event);
|
||||
}
|
||||
}
|
||||
}
|
||||
public static var CHANGE_PLAY_MODE_EVENT :String = "CHANGE_PLAY_MODE_EVENT";
|
||||
private var _registerIt:uint;
|
||||
public static var ORGIN_VIDEO_WIDTH:int = 480;
|
||||
public static var ORGIN_VIDEO_HEIGHT:int = 360;
|
||||
|
||||
|
||||
private function startMiniYY():void
|
||||
{
|
||||
if(!flv)
|
||||
{
|
||||
flv = new YYFLV();
|
||||
flv.setFlvConfig(0, 2, 2000);
|
||||
flv.setFlvConfig(0, 4, 800);
|
||||
flv.setFlvConfig(0, 11, 16800);
|
||||
flv.setFlvConfig(0, 13, 30);
|
||||
flv.setFlvConfig(0, 14, 2);
|
||||
flv.addEventListener(FlvEvent.PLAY_STATUS, onPlayStatus);
|
||||
flv.addEventListener(FlvEvent.PLAY_VIDEO, onPlayVideo);
|
||||
flv.addEventListener(FlvEvent.MULTI_VIDEOS, onNotifyMultiVideo);
|
||||
flv.addEventListener(FlvEvent.FLV_LOG,onFlvLog);
|
||||
flv.setLogMode(2);
|
||||
}
|
||||
flv.startYY(sid, subsid, appid, sceneId);
|
||||
flv.removeMuteUid(BaseService.getInstance().getCurrentUserInfo().uid);
|
||||
flv.addMuteUid(BaseService.getInstance().getCurrentUserInfo().uid);
|
||||
}
|
||||
public function stopSubscribeVideo(uid:uint):void{
|
||||
if(uid == BaseService.getInstance().getCurrentUserInfo().uid)
|
||||
return;
|
||||
YY.instance.video.stopSubscribeVideo(uid);
|
||||
var video:* = videos.get(uid);
|
||||
var event : PKVideoEvent = new PKVideoEvent(PKVideoEvent.VIDEO_REMOVED);
|
||||
event.data = {video:video,uid:uid};
|
||||
dispatchEvent(event);
|
||||
videos.remove(uid);
|
||||
}
|
||||
private function closeAllVideos():void
|
||||
{
|
||||
for each(var uid:uint in videos.keys()){
|
||||
var video:* = videos.get(uid);
|
||||
stopSubscribeVideo(uid);
|
||||
}
|
||||
videos.clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,807 @@
|
||||
package com.yy.vip.pk.video.service
|
||||
{
|
||||
import com.yy.flash.flv.FlvEvent;
|
||||
import com.yy.flash.flv.FlvMsg;
|
||||
import com.yy.flash.flv.FlvPlayStatus;
|
||||
import com.yy.flash.flv.VideoTypeInfo;
|
||||
import com.yy.flash.flv.YYFLV;
|
||||
import com.yy.flash.flv.utils.YYHashMap;
|
||||
import com.yy.vip.pk.base.components.MyAlert;
|
||||
import com.yy.vip.pk.event.CommonEvent;
|
||||
import com.yy.vip.pk.inter.IAppService;
|
||||
import com.yy.vip.pk.service.BaseService;
|
||||
import com.yy.vip.pk.service.DataReportService;
|
||||
import com.yy.vip.pk.service.JsService;
|
||||
import com.yy.vip.pk.util.JSONUtil;
|
||||
import com.yy.vip.pk.util.Tracer;
|
||||
import com.yy.vip.pk.video.event.MasterSpeakEvent;
|
||||
import com.yy.vip.pk.video.event.PKVideoEvent;
|
||||
import com.yy.vip.pk.video.util.ConfigVideo;
|
||||
|
||||
import flash.events.Event;
|
||||
import flash.events.EventDispatcher;
|
||||
import flash.events.TimerEvent;
|
||||
import flash.geom.Point;
|
||||
import flash.media.Video;
|
||||
import flash.utils.clearInterval;
|
||||
import flash.utils.clearTimeout;
|
||||
import flash.utils.setInterval;
|
||||
import flash.utils.setTimeout;
|
||||
|
||||
import org.flexlite.domUI.components.Alert;
|
||||
import org.flexlite.domUI.events.CloseEvent;
|
||||
|
||||
import yy.YY;
|
||||
import yy.events.AudioEvent;
|
||||
import yy.events.ChannelEvent;
|
||||
import yy.events.ChannelMicListEvent;
|
||||
import yy.events.VideoEvent;
|
||||
|
||||
public class VideoService_v2 extends EventDispatcher
|
||||
{
|
||||
private static var _APP_SERVICE:IAppService;
|
||||
private var flv:YYFLV = null;
|
||||
private var clientModeVideos:YYHashMap = new YYHashMap();
|
||||
private var miniyyModeVideos:YYHashMap = new YYHashMap();
|
||||
private var sid:uint = 80000;
|
||||
private var subsid:uint = 2261570816;
|
||||
private var appid:uint = 0; //15013=娱乐 10057=虎牙
|
||||
private var sceneId:uint = 600; //100=娱乐首页 101=娱乐直播间 200=虎牙首页 201=虎牙直播间 300=财经首页 301=财经直播间 400=精彩世界 500=环球教育 600=vippk
|
||||
private static var _instance:VideoService_v2;
|
||||
private var isPublish:Boolean;
|
||||
|
||||
public static function set APP_SERVICE(value:IAppService):void
|
||||
{
|
||||
_APP_SERVICE = value;
|
||||
|
||||
}
|
||||
|
||||
public static function getInstance():VideoService_v2{
|
||||
if(!_instance)
|
||||
_instance = new VideoService_v2();
|
||||
|
||||
return _instance;
|
||||
}
|
||||
/*[15:51:13:50] FlvLog.setFlvConfig appid=0 key=2 val=2000
|
||||
[15:51:13:50] FlvLog.setFlvConfig appid=0 key=3 val=1200
|
||||
[15:51:13:50] FlvLog.setFlvConfig appid=0 key=10 val=1300
|
||||
[15:51:13:50] FlvLog.setFlvConfig appid=0 key=4 val=800
|
||||
[15:51:13:50] FlvLog.setFlvConfig appid=0 key=11 val=16800
|
||||
[15:51:13:51] FlvLog.setFlvConfig appid=0 key=9 val=2000*/
|
||||
public function VideoService_v2(){
|
||||
|
||||
if(BaseService.getInstance().configXML.palyModeVideo == undefined || String(BaseService.getInstance().configXML.palyModeVideo) == "0")
|
||||
{
|
||||
_playMode = CLIENT_MODE;
|
||||
}
|
||||
else if(BaseService.getInstance().configXML.palyModeVideo && String(BaseService.getInstance().configXML.palyModeVideo) == "1"){
|
||||
_playMode = WEB_MODE;
|
||||
}
|
||||
YY.instance.video.removeEventListener(VideoEvent.VIDEO_LOCK_STATUS,lockStatusHandler);
|
||||
YY.instance.video.addEventListener(VideoEvent.VIDEO_LOCK_STATUS,lockStatusHandler);
|
||||
|
||||
Tracer.debugLog("SetStreamMgrConfig : " + "anchor-htmlvippk","视频开播");
|
||||
//YY.instance.video.SetStreamMgrConfig("anchor-htmlvippk",true);
|
||||
Tracer.debugLog("lock ","视频开播");
|
||||
var res:Object = YY.instance.video.lock();
|
||||
lockStatus = res.ret;
|
||||
lockStatusHandler();
|
||||
|
||||
Tracer.debugLog("视频调用lock,ret:"+res.ret,Tracer.SYS_LOG);
|
||||
stopPublishTcp();
|
||||
YY.instance.video.addEventListener(VideoEvent.PUBLISH_STATUS,publishStatusHandler);
|
||||
YY.instance.video.addEventListener(VideoEvent.SUBSCRIBE_STATUS,subscribeStatusHandler);
|
||||
YY.instance.video.addEventListener(VideoEvent.CAMERA_STATUS,cameraStatusHandler);
|
||||
YY.instance.audio.addEventListener(AudioEvent.AUDIO_LISTEN_VOLUME_CHANGED,volumeChangeHandler);
|
||||
YY.instance.audio.addEventListener(AudioEvent.AUDIO_SPEAKER_STATUE_CHANGED,muteChangeHandler);
|
||||
YY.instance.channel.micList.addEventListener(ChannelMicListEvent.CLEAR,clearMicHandler);
|
||||
YY.instance.channel.micList.addEventListener(ChannelMicListEvent.USER_LEAVE,userLeaveMic);
|
||||
YY.instance.channel.addEventListener(ChannelEvent.USER_LEAVE_CHANNEL,levelChanleHandler);
|
||||
YY.instance.channel.micList.addEventListener(ChannelMicListEvent.SPEAKING_STATE_CHANGED,masterChangeMic);
|
||||
/*YY.instance.video.addEventListener(VideoEvent.VIDEO_VIEWER_STREAM_INFO,videoViewerStreamInfoHandler);
|
||||
YY.instance.video.addEventListener(VideoEvent.VIDEO_STREAMMGR_ANCHOR_CONFIG,streamAnchorConfigHandler);*/
|
||||
|
||||
if(!hasRegist && playMode == WEB_MODE)
|
||||
{
|
||||
hasRegist = true;
|
||||
soundInit();
|
||||
}
|
||||
Tracer.debugLog("SetForceUseAnchorStream : " + true,"视频开播");
|
||||
//YY.instance.video.SetForceUseAnchorStream(true);
|
||||
|
||||
this.startYY(BaseService.getInstance().channelInfo.longId,BaseService.getInstance().subChannelInfo.longId,BaseService.APP_ID);
|
||||
}
|
||||
|
||||
private function streamAnchorConfigHandler(event : VideoEvent):void
|
||||
{
|
||||
|
||||
var jonStr:String = JSONUtil.encode(event.eventData);
|
||||
|
||||
//YY.instance.video.SwitchClariryLevel(
|
||||
Tracer.debugLog("streamAnchorConfigHandler : " + jonStr,"视频开播");
|
||||
}
|
||||
|
||||
private var lockIt:int;
|
||||
private function lockStatusHandler(event:VideoEvent = null):void
|
||||
{
|
||||
if(event)
|
||||
lockStatus = event.eventData.status;
|
||||
|
||||
Tracer.debugLog("视频调用lock,返回status:" + lockStatus,Tracer.SYS_LOG,true);
|
||||
if(lockStatus != 0)//失败
|
||||
{
|
||||
var alert:Alert = MyAlert.show("视频组件加载失败\n请升级YY或重新启动YY客户端","",function(e:CloseEvent):void{
|
||||
if(e.detail == Alert.FIRST_BUTTON){
|
||||
JsService.getInstance().reloadPage();
|
||||
}
|
||||
},"重新进入频道");
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
YY.instance.video.removeEventListener(VideoEvent.VIDEO_LOCK_STATUS,lockStatusHandler);
|
||||
clearTimeout(lockIt);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private function videoViewerStreamInfoHandler(event: VideoEvent):void
|
||||
{
|
||||
var jonStr:String = JSONUtil.encode(event.eventData);
|
||||
Tracer.debugLog("videoViewerStreamInfoHandler : " + jonStr,"视频开播");
|
||||
}
|
||||
|
||||
private function soundInit():void
|
||||
{
|
||||
if(flv)
|
||||
{
|
||||
YY.instance.audio.RegisterAudioController(BaseService.APP_ID);
|
||||
clearInterval(_registerIt);
|
||||
_registerIt =setInterval(function handler():void{
|
||||
if(playMode == WEB_MODE)
|
||||
YY.instance.audio.RegisterAudioController(BaseService.APP_ID);
|
||||
},5000);
|
||||
|
||||
var isturnonVolume:* = YY.instance.audio.isListenTurnOn().isturnon;
|
||||
var volume :Number = YY.instance.audio.getListenVolume().volume * 100;
|
||||
if(!isNaN(volume))
|
||||
flv.adjustVolume(volume);
|
||||
if(!isNaN(isturnonVolume) && isturnonVolume == false)
|
||||
flv.adjustVolume(0);
|
||||
}
|
||||
}
|
||||
|
||||
private function userLeaveMic(event:ChannelMicListEvent):void
|
||||
{
|
||||
if(event.eventData.uid == BaseService.getInstance().getCurrentUserInfo().uid){
|
||||
Tracer.debugLog("用户下麦,停止发布视频",Tracer.SYS_LOG,true);
|
||||
stopPublishTcp();
|
||||
}
|
||||
else
|
||||
{
|
||||
stopSubscribeVideo(event.eventData.uid);
|
||||
}
|
||||
|
||||
}
|
||||
/**
|
||||
* 有用户leave
|
||||
**/
|
||||
private function levelChanleHandler(event:ChannelEvent):void
|
||||
{
|
||||
|
||||
if(event.eventData.uid == BaseService.getInstance().getCurrentUserInfo().uid){
|
||||
Tracer.debugLog("用户离开,停止发布视频",Tracer.SYS_LOG,true);
|
||||
stopPublishTcp();
|
||||
}
|
||||
else{
|
||||
this.stopSubscribeVideo(event.eventData.uid);
|
||||
}
|
||||
}
|
||||
|
||||
private function clearMicHandler(event:ChannelMicListEvent):void
|
||||
{
|
||||
Tracer.debugLog("清理麦序,停止发布视频",Tracer.CLIENT_ACT_LOG,true);
|
||||
stopPublishTcp();
|
||||
closeAllVideos();
|
||||
|
||||
}
|
||||
|
||||
protected function onFlvLog(event:FlvEvent):void
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private function muteChangeHandler(event:AudioEvent):void
|
||||
{
|
||||
if(!flv){
|
||||
return;
|
||||
}
|
||||
if( playMode == WEB_MODE){
|
||||
var mute:*;
|
||||
if(event.eventData is String)
|
||||
mute = JSONUtil.decode(event.eventData.toString()).mute;
|
||||
else
|
||||
mute = event.eventData.mute;
|
||||
|
||||
if(!isNaN(mute) && mute == true){
|
||||
flv.adjustVolume(0);
|
||||
}
|
||||
else
|
||||
{
|
||||
var volume :Number = YY.instance.audio.getListenVolume().volume * 100;
|
||||
if(!isNaN(volume))
|
||||
flv.adjustVolume(volume)
|
||||
else
|
||||
flv.adjustVolume(100)
|
||||
}
|
||||
|
||||
flv.removeMuteUid(BaseService.getInstance().getCurrentUserInfo().uid);
|
||||
flv.addMuteUid(BaseService.getInstance().getCurrentUserInfo().uid);
|
||||
}
|
||||
}
|
||||
|
||||
private function volumeChangeHandler(event:AudioEvent):void
|
||||
{
|
||||
if(!flv){
|
||||
return
|
||||
}
|
||||
if( playMode == WEB_MODE){
|
||||
var volume:Number = 1;
|
||||
if(event.eventData is String)
|
||||
volume = (JSONUtil.decode(event.eventData.toString())).volume * 100 ;
|
||||
else
|
||||
volume = event.eventData.volume;
|
||||
|
||||
if(!isNaN(volume))
|
||||
flv.adjustVolume(volume)
|
||||
else
|
||||
flv.adjustVolume(100)
|
||||
|
||||
flv.removeMuteUid(BaseService.getInstance().getCurrentUserInfo().uid);
|
||||
flv.addMuteUid(BaseService.getInstance().getCurrentUserInfo().uid);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function startYY(sid:uint,subsid:uint,appid:uint):void{
|
||||
|
||||
this.sid = sid;
|
||||
this.subsid = subsid;
|
||||
this.appid = this.appid;
|
||||
|
||||
if(playMode == WEB_MODE){
|
||||
if(flv)
|
||||
flv.stopYY();
|
||||
startMiniYY();
|
||||
soundInit();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function onPlayVideo(event:FlvEvent):void {
|
||||
var uid:uint = event.data.uid;
|
||||
var v:Video = event.data.video;
|
||||
Tracer.debugLog('onPlayVideo uid=' + uid,Tracer.CLIENT_ACT_LOG);
|
||||
miniyyModeVideos.put(uid, v);
|
||||
var e : PKVideoEvent;
|
||||
if(uid != BaseService.getInstance().getCurrentUserInfo().uid)
|
||||
{
|
||||
closeSubscribeClienModeVideo(uid);
|
||||
e = new PKVideoEvent(PKVideoEvent.VIDEO_ADDED);
|
||||
e.data = {video:v,uid:uid};
|
||||
dispatchEvent(e);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
flv.removeMuteUid(BaseService.getInstance().getCurrentUserInfo().uid);
|
||||
flv.addMuteUid(BaseService.getInstance().getCurrentUserInfo().uid);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected function soundTimeOutHandler(event:TimerEvent):void
|
||||
{
|
||||
|
||||
if(playMode == CLIENT_MODE)
|
||||
return;
|
||||
this.changeClientMode();
|
||||
}
|
||||
|
||||
public function onPlayStatus(event:FlvEvent):void {
|
||||
var uid:uint = event.data.uid;
|
||||
var status:uint = event.data.status;
|
||||
var v:* = event.data.video;
|
||||
Tracer.debugLog('onPlayStatus uid=' + uid + ' status=' + FlvPlayStatus.getStatusStr(status),Tracer.CLIENT_ACT_LOG);
|
||||
if(uid == BaseService.getInstance().getCurrentUserInfo().uid){
|
||||
flv.removeMuteUid(BaseService.getInstance().getCurrentUserInfo().uid);
|
||||
flv.addMuteUid(BaseService.getInstance().getCurrentUserInfo().uid);
|
||||
}
|
||||
var e:PKVideoEvent;
|
||||
switch (status) {
|
||||
case FlvPlayStatus.FLV_STATUS_STOP:
|
||||
v = miniyyModeVideos.get(uid);
|
||||
if(uid != BaseService.getInstance().getCurrentUserInfo().uid)
|
||||
{
|
||||
e = new PKVideoEvent(PKVideoEvent.VIDEO_REMOVED);
|
||||
e.data = {video:v,uid:uid};
|
||||
dispatchEvent(e);
|
||||
miniyyModeVideos.remove(uid);
|
||||
stopSubscribeVideo(uid);
|
||||
}
|
||||
|
||||
break;
|
||||
case FlvPlayStatus.FLV_STATUS_VIDEO_RESOLUTION_CHANGED:
|
||||
|
||||
v = miniyyModeVideos.get(uid);
|
||||
e = new PKVideoEvent(PKVideoEvent.VIDEO_RESIZED);
|
||||
e.data = {video:v,uid:uid};
|
||||
dispatchEvent(e);
|
||||
|
||||
if(uid != BaseService.getInstance().getCurrentUserInfo().uid)
|
||||
{
|
||||
|
||||
e = new PKVideoEvent(PKVideoEvent.VIDEO_ADDED);
|
||||
e.data = {video:v,uid:uid};
|
||||
dispatchEvent(e);
|
||||
}
|
||||
break;
|
||||
case FlvPlayStatus.FLV_STATUS_PLAYING:
|
||||
if(uid != BaseService.getInstance().getCurrentUserInfo().uid)
|
||||
{
|
||||
if(v)
|
||||
miniyyModeVideos.put(uid,v);
|
||||
|
||||
v = miniyyModeVideos.get(uid);
|
||||
e = new PKVideoEvent(PKVideoEvent.VIDEO_ADDED);
|
||||
e.data = {video:v,uid:uid};
|
||||
dispatchEvent(e);
|
||||
}
|
||||
break;
|
||||
case FlvPlayStatus.AUDIO_STATUS_START:
|
||||
|
||||
break;
|
||||
case FlvPlayStatus.AUDIO_STATUS_STOP:
|
||||
|
||||
break;
|
||||
case FlvPlayStatus.AUDIO_VIDEO_OUT_OF_SYNC:
|
||||
this.changeClientMode();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private function closeSubscribeClienModeVideo(uid:uint):void
|
||||
{
|
||||
YY.instance.video.stopSubscribeVideo(uid);
|
||||
clientModeVideos.remove(uid);
|
||||
clearTimeout(_tryItMap[uid]);
|
||||
var event : PKVideoEvent = new PKVideoEvent(PKVideoEvent.VIDEO_REMOVED);
|
||||
event.data = {video:null,uid:uid};
|
||||
dispatchEvent(event);
|
||||
}
|
||||
|
||||
public function onMessage(msg:FlvMsg):void {
|
||||
trace("onMessage type=" + msg.getType() + " msg=" + msg.getMsg());
|
||||
}
|
||||
|
||||
public function flvLog(str:String):void {
|
||||
}
|
||||
|
||||
public function onNotifyMultiVideo(e:FlvEvent):void {
|
||||
trace("onNotifyMultiVideo");
|
||||
var needPlay:Boolean = e.data.needPlay;
|
||||
var appId:uint = e.data.appId;
|
||||
var videoTypeInfos:Vector.<VideoTypeInfo> = e.data.videoTypeInfos;
|
||||
if (needPlay){
|
||||
var channelId:uint = appId;
|
||||
var str:Array = [];
|
||||
var maxCodeRate:uint = 0;
|
||||
var maxCodeRateId:uint = 0;
|
||||
for each(var vt:VideoTypeInfo in videoTypeInfos){
|
||||
str.push(vt.channelId + '-' + vt.codeRate);
|
||||
if (vt.codeRate > maxCodeRate) {
|
||||
maxCodeRate = vt.codeRate;
|
||||
maxCodeRateId = vt.channelId;
|
||||
}
|
||||
|
||||
if (vt.channelType === 0) {
|
||||
maxCodeRateId = vt.channelId;
|
||||
break;
|
||||
}
|
||||
}
|
||||
flv.playChannel(maxCodeRateId);
|
||||
}
|
||||
}
|
||||
|
||||
public function onAudioSample(sample:Number):void {
|
||||
}
|
||||
|
||||
public function onAnchorStop(uid:uint):void{
|
||||
trace('onAnchorStop uid=' + uid);
|
||||
}
|
||||
|
||||
public function onAudioPlaySample(uid:uint, sample:Number):void {
|
||||
}
|
||||
|
||||
public function publishTcp(uid:uint):Object
|
||||
{
|
||||
|
||||
this.changeClientMode();
|
||||
stopPublishTcp();
|
||||
if(ORGIN_VIDEO_WIDTH == 480)
|
||||
ConfigVideo.setPublishVideo_480x360_Tcp();
|
||||
else if(ORGIN_VIDEO_WIDTH == 320)
|
||||
ConfigVideo.setPublishVideo_320x240_Tcp();
|
||||
|
||||
ConfigVideo.configEncode();
|
||||
//YY.instance.video.SetStreamMgrVideoPublishSetting("320x240");
|
||||
/*var cameraList :Object = YY.instance.video.getCameraList();
|
||||
var _camera :Object = YY.instance.video.getCurrentCamera();*/
|
||||
|
||||
var _cameraIndex:int = 0;
|
||||
|
||||
/*if(_camera.ret == 0)
|
||||
_cameraIndex = _camera.camera;
|
||||
|
||||
if(_cameraIndex == -1)
|
||||
_cameraIndex = 0;*/
|
||||
|
||||
var point:Point = new Point(0,0);
|
||||
var res:Object = YY.instance.video.startPublishVideoTcpTransfer(point.x,point.y,ORGIN_VIDEO_WIDTH,ORGIN_VIDEO_HEIGHT,_cameraIndex,USE_FLV,true);
|
||||
Tracer.debugLog("uid:" + uid + ",开始发布视频,ret:"+res.ret,Tracer.SYS_LOG,true);
|
||||
if(!res)
|
||||
res = {ret:50001};
|
||||
|
||||
if(res && (Number(res.ret) == 45061 || Number(res.ret) == 45065))
|
||||
{
|
||||
_cameraIndex++;
|
||||
for(var i:uint = 0;i<3;i++)
|
||||
{
|
||||
res = YY.instance.video.startPublishVideoTcpTransfer(point.x,point.y,ORGIN_VIDEO_WIDTH,ORGIN_VIDEO_HEIGHT,_cameraIndex,USE_FLV,true);
|
||||
if(res && Number(res.ret) != 45061 && Number(res.ret) != 45065 ){
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(res && (Number(res.ret) == 45061 || Number(res.ret) == 45065))
|
||||
{
|
||||
Tracer.debugLog("摄像头不可用哦!请打开视频设置下呗",Tracer.CLIENT_ACT_LOG)
|
||||
MyAlert.show("摄像头不可用哦!请打开视频设置下呗");
|
||||
YY.instance.video.stopPublish();
|
||||
DataReportService.getInstance().reportMetricsReturnCode(50134,"摄像头不可用",10,res.ret.toString());
|
||||
res.ret = 45062;
|
||||
return res;
|
||||
|
||||
}
|
||||
|
||||
if(res && Number(res.ret) == 984832)
|
||||
{
|
||||
Tracer.debugLog("发布视频api既然超时了,重试下呗",Tracer.CLIENT_ACT_LOG,true);
|
||||
YY.instance.video.stopPublish();
|
||||
res.ret = 984832;
|
||||
DataReportService.getInstance().reportMetricsReturnCode(50134,"开播api超时",10,res.ret.toString());
|
||||
return res;
|
||||
}
|
||||
|
||||
if(res && Number(res.ret) == 0)
|
||||
{
|
||||
isPublish = true;
|
||||
clientModeVideos.put(BaseService.getInstance().getCurrentUserInfo().uid,res.video);
|
||||
var e :PKVideoEvent= new PKVideoEvent(PKVideoEvent.VIDEO_ADDED);
|
||||
e.data = {video:res.video,uid:BaseService.getInstance().getCurrentUserInfo().uid};
|
||||
dispatchEvent(e);
|
||||
this.startPublishTime = new Date().time;
|
||||
clearTimeout(this.startPublishTimeIt);
|
||||
this.startPublishTimeIt = setTimeout(function handler():void{
|
||||
clearTimeout(startPublishTimeIt);
|
||||
startPublishTime = new Date().time;
|
||||
dataReport();
|
||||
},10 * 1000 * 60);
|
||||
DataReportService.getInstance().reportMetricsReturnCode(50134,"开播成功",10,res.ret.toString());
|
||||
}
|
||||
else
|
||||
{
|
||||
Tracer.debugLog("uid:" + uid + ",操作失败,请检查设备或重进频道再试:" + res.ret,Tracer.ERROR_LOG,true);
|
||||
MyAlert.show("操作失败,请检查设备或重进频道再试 :" + res.ret);
|
||||
isPublish = false;
|
||||
DataReportService.getInstance().reportMetricsReturnCode(50134,"开播失败",10,res.ret.toString())
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
public function stopPublishTcp():void
|
||||
{
|
||||
if(!isPublish)
|
||||
return;
|
||||
var res :Object = YY.instance.video.stopPublish();
|
||||
Tracer.debugLog("调用停止发布视频返回结果:"+res.ret,Tracer.CLIENT_ACT_LOG,true);
|
||||
clientModeVideos.remove(BaseService.getInstance().getCurrentUserInfo().uid);
|
||||
isPublish = false;
|
||||
var endPublishTime :Number = new Date().time;
|
||||
clearTimeout(this.startPublishTimeIt);
|
||||
if((endPublishTime - this.startPublishTime)/1000/60 >= 10)
|
||||
{
|
||||
dataReport();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private function publishStatusHandler(event:VideoEvent):void
|
||||
{
|
||||
if(event.eventData.status !=0)
|
||||
{
|
||||
dispatchEvent(new CommonEvent(CommonEvent.PUBLISH_FAIL));
|
||||
Tracer.debugLog("发布视频失败:" + event.eventData.status,Tracer.ERROR_LOG,true);
|
||||
MyAlert.show("发布视频失败,请重进频道再试" );
|
||||
isPublish = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
Tracer.debugLog("发布视频成功:" + event.eventData.status,Tracer.ERROR_LOG,true);
|
||||
|
||||
}
|
||||
}
|
||||
private var cit:int;
|
||||
private var chestKeyMarInt:uint;
|
||||
private var hasRegist:Boolean;
|
||||
|
||||
private function cameraStatusHandler(event:VideoEvent):void
|
||||
{
|
||||
clearTimeout(cit);
|
||||
cit = setTimeout(function dd():void{
|
||||
clearTimeout(cit);
|
||||
|
||||
if(event.eventData.status == 1)
|
||||
{
|
||||
MyAlert.show("摄像头给占用了哦!请打开视频设置下呗");
|
||||
|
||||
}
|
||||
else if(event.eventData.status == 2)
|
||||
{
|
||||
MyAlert.show("您的摄像头暂不能支持哦!请打开视频设置下呗");
|
||||
|
||||
}
|
||||
Tracer.debugLog("摄像头状态:" + event.eventData.status,Tracer.CLIENT_ACT_LOG,true);
|
||||
var e:CommonEvent = new CommonEvent(CommonEvent.CAMERA_STATUS);
|
||||
dispatchEvent(e);
|
||||
|
||||
},3000);
|
||||
}
|
||||
private function startStartSubscribeVideoTcpTransfer(uid:uint):void{
|
||||
if(uid == 0)
|
||||
return;
|
||||
closeSubscribeClienModeVideo(uid);
|
||||
var res :Object = YY.instance.video.startSubscribeVideoTcpTransfer(0,0,ORGIN_VIDEO_WIDTH,ORGIN_VIDEO_HEIGHT,uid,USE_FLV,true);
|
||||
Tracer.debugLog("订阅主播视频,uid:" + uid + ",ret:" + res.ret ,Tracer.CLIENT_ACT_LOG,true);
|
||||
if(res.ret == 0)
|
||||
{
|
||||
clientModeVideos.put(uid, res.video);
|
||||
var event2 :PKVideoEvent= new PKVideoEvent(PKVideoEvent.VIDEO_ADDED);
|
||||
event2.data = {video:res.video,uid:uid};
|
||||
dispatchEvent(event2);
|
||||
clearTimeout(_tryItMap[uid]);
|
||||
}
|
||||
else
|
||||
{
|
||||
_tryItMap[uid] = setTimeout(function handler(...params):void{
|
||||
clearTimeout(_tryItMap[params[0]]);
|
||||
startStartSubscribeVideoTcpTransfer(params[0]);
|
||||
},4000,uid);
|
||||
}
|
||||
}
|
||||
private var _tryItMap: Object = {};
|
||||
private function subscribeStatusHandler(event:VideoEvent):void
|
||||
{
|
||||
Tracer.debugLog("主播上下视频通知,uid:"+event.eventData.uid + ",status:"+event.eventData.status,Tracer.CLIENT_ACT_LOG,true);
|
||||
var e:CommonEvent = new CommonEvent(CommonEvent.SUBSCRIBE_CHANGE);
|
||||
e.data = event.eventData;
|
||||
dispatchEvent(e);
|
||||
if(playMode == CLIENT_MODE)
|
||||
{
|
||||
if(event.eventData.status == 0)
|
||||
{
|
||||
checkVideo(event.eventData.uid);
|
||||
}
|
||||
else
|
||||
{
|
||||
closeSubscribeClienModeVideo(event.eventData.uid);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function checkVideo(uid:uint):void{
|
||||
|
||||
var event : PKVideoEvent;
|
||||
if(uid != BaseService.getInstance().getCurrentUserInfo().uid)
|
||||
{
|
||||
var miniYYFLag :Boolean = false;
|
||||
if(miniyyModeVideos.getValue(uid))//有效
|
||||
{
|
||||
miniYYFLag = true;
|
||||
closeSubscribeClienModeVideo(uid);
|
||||
event = new PKVideoEvent(PKVideoEvent.VIDEO_ADDED);
|
||||
event.data = {video:miniyyModeVideos.getValue(uid),uid:uid};
|
||||
dispatchEvent(event);
|
||||
}
|
||||
else if(clientModeVideos.getValue(uid))//有效
|
||||
{
|
||||
event = new PKVideoEvent(PKVideoEvent.VIDEO_ADDED);
|
||||
event.data = {video:clientModeVideos.getValue(uid),uid:uid};
|
||||
dispatchEvent(event);
|
||||
}
|
||||
else
|
||||
{
|
||||
if(playMode == CLIENT_MODE)
|
||||
startStartSubscribeVideoTcpTransfer(uid);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public static var CHANGE_PLAY_MODE_EVENT :String = "CHANGE_PLAY_MODE_EVENT";
|
||||
public static var WEB_MODE :uint = 0;
|
||||
public static var CLIENT_MODE :uint = 1;
|
||||
private var _playMode:int = CLIENT_MODE;
|
||||
private var _registerIt:uint;
|
||||
public static var ORGIN_VIDEO_WIDTH:int = 320;
|
||||
public static var ORGIN_VIDEO_HEIGHT:int = 240;
|
||||
private var USE_FLV:Boolean = false;
|
||||
private var _muteIt:uint;
|
||||
public function changeClientMode():void{
|
||||
if(playMode == CLIENT_MODE)
|
||||
return;
|
||||
playMode = CLIENT_MODE;
|
||||
clearInterval(_registerIt);
|
||||
clearInterval(_muteIt);
|
||||
|
||||
if(flv)
|
||||
flv.stopYY();
|
||||
closeAllVideos();
|
||||
|
||||
YY.instance.audio.UnregisterAudioController(BaseService.APP_ID);
|
||||
var event :Event = new Event(CHANGE_PLAY_MODE_EVENT);
|
||||
dispatchEvent(event)
|
||||
}
|
||||
public function changeWebMode():void{
|
||||
if(playMode == WEB_MODE)
|
||||
return;
|
||||
playMode = WEB_MODE;
|
||||
closeAllVideos();
|
||||
startMiniYY();
|
||||
|
||||
soundInit();
|
||||
var event:Event = new Event(CHANGE_PLAY_MODE_EVENT);
|
||||
dispatchEvent(event);
|
||||
|
||||
}
|
||||
|
||||
private function startMiniYY():void
|
||||
{
|
||||
if(!flv)
|
||||
{
|
||||
flv = new YYFLV();
|
||||
flv.setFlvConfig(0, 2, 2000);
|
||||
flv.setFlvConfig(0, 4, 800);
|
||||
flv.setFlvConfig(0, 11, 16800);
|
||||
flv.setFlvConfig(0, 13, 30);
|
||||
flv.setFlvConfig(0, 14, 2);
|
||||
flv.addEventListener(FlvEvent.PLAY_STATUS, onPlayStatus);
|
||||
flv.addEventListener(FlvEvent.PLAY_VIDEO, onPlayVideo);
|
||||
flv.addEventListener(FlvEvent.MULTI_VIDEOS, onNotifyMultiVideo);
|
||||
flv.addEventListener(FlvEvent.FLV_LOG,onFlvLog);
|
||||
flv.setLogMode(2);
|
||||
}
|
||||
|
||||
flv.startYY(this.sid, this.subsid, this.appid, this.sceneId,BaseService.getInstance().getCurrentUserInfo().uid);
|
||||
flv.removeMuteUid(BaseService.getInstance().getCurrentUserInfo().uid);
|
||||
flv.addMuteUid(BaseService.getInstance().getCurrentUserInfo().uid);
|
||||
|
||||
clearInterval(_muteIt);
|
||||
_muteIt = setInterval(function handler():void{
|
||||
flv.removeMuteUid(BaseService.getInstance().getCurrentUserInfo().uid);
|
||||
flv.addMuteUid(BaseService.getInstance().getCurrentUserInfo().uid);
|
||||
},3000);
|
||||
}
|
||||
|
||||
|
||||
public function stopSubscribeVideo(uid:uint):void{
|
||||
if(uid == BaseService.getInstance().getCurrentUserInfo().uid)
|
||||
return;
|
||||
|
||||
clearTimeout(_tryItMap[uid]);
|
||||
YY.instance.video.stopSubscribeVideo(uid);
|
||||
var event : PKVideoEvent = new PKVideoEvent(PKVideoEvent.VIDEO_REMOVED);
|
||||
event.data = {video:null,uid:uid};
|
||||
dispatchEvent(event);
|
||||
if(miniyyModeVideos.containsKey(uid) || clientModeVideos.containsKey(uid))
|
||||
Tracer.debugLog("停止订阅视频:" + uid,Tracer.CLIENT_ACT_LOG,true);
|
||||
miniyyModeVideos.remove(uid);
|
||||
clientModeVideos.remove(uid);
|
||||
}
|
||||
private function closeAllVideos():void
|
||||
{
|
||||
var uid:uint;
|
||||
var video:*;
|
||||
for each(uid in clientModeVideos.keys()){
|
||||
video = clientModeVideos.get(uid);
|
||||
stopSubscribeVideo(uid);
|
||||
}
|
||||
for each(uid in miniyyModeVideos.keys()){
|
||||
video = miniyyModeVideos.get(uid);
|
||||
stopSubscribeVideo(uid);
|
||||
}
|
||||
miniyyModeVideos.clear();
|
||||
clientModeVideos.clear();
|
||||
}
|
||||
|
||||
public function get playMode():int{
|
||||
return BaseService.getInstance().isWebYY ?CLIENT_MODE:_playMode;
|
||||
}
|
||||
public function set playMode(value:int):void{
|
||||
this._playMode = value;
|
||||
}
|
||||
private var _oldPlayMode:uint;
|
||||
private var _isCloseAllVideoTra:Boolean = false;
|
||||
private var startPublishTime:Number;
|
||||
private var startPublishTimeIt:uint;
|
||||
public function closeAllVideoTra():void{
|
||||
clearInterval(_registerIt);
|
||||
clearInterval(_muteIt);
|
||||
if(flv)
|
||||
flv.stopYY();
|
||||
closeAllVideos();
|
||||
_oldPlayMode = _playMode;
|
||||
_isCloseAllVideoTra =true;
|
||||
_playMode = -1;
|
||||
YY.instance.audio.UnregisterAudioController(BaseService.APP_ID);
|
||||
|
||||
}
|
||||
public function openAllVideoTra():void{
|
||||
if(_oldPlayMode == WEB_MODE)
|
||||
{
|
||||
changeWebMode();
|
||||
}
|
||||
else if(_oldPlayMode == CLIENT_MODE)
|
||||
{
|
||||
changeClientMode();
|
||||
}
|
||||
_isCloseAllVideoTra =false;
|
||||
}
|
||||
public function isCloseAllVideoTra():Boolean{
|
||||
return _isCloseAllVideoTra;
|
||||
}
|
||||
private function dataReport():void
|
||||
{
|
||||
DataReportService.getInstance().dataReport(BaseService.getInstance().getCurrentUserInfo().uid,DataReportService.DATA_TYPE_VIDEO_PUBLISH_TIME,"开播大于10分钟");
|
||||
}
|
||||
|
||||
public function getVideoByUid(uid:uint):Video{
|
||||
if(playMode == CLIENT_MODE)
|
||||
return clientModeVideos.get(uid);
|
||||
else if(playMode == WEB_MODE)
|
||||
return miniyyModeVideos.get(uid);
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 麦序音频变化
|
||||
* */
|
||||
private var _speakingDatas:Object = {};
|
||||
private var lockStatus:Object;
|
||||
private function masterChangeMic(e:ChannelMicListEvent):void{
|
||||
_speakingDatas[e.eventData.uid] = e.eventData.speaking;
|
||||
var event:MasterSpeakEvent = new MasterSpeakEvent(MasterSpeakEvent.MASTER_SPEAKING_CHANGED,e.eventData.uid,e.eventData.speaking);
|
||||
dispatchEvent(event);
|
||||
}
|
||||
|
||||
public function getSpeakingData(_userId:uint):Object
|
||||
{
|
||||
return _speakingDatas[_userId];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,131 @@
|
||||
package com.yy.vip.pk.video.util
|
||||
{
|
||||
import com.yy.vip.pk.service.BaseService;
|
||||
|
||||
import yy.YY;
|
||||
import yy.data.VideoConfigAttr;
|
||||
import yy.data.VideoPictureRatioAttr;
|
||||
import yy.data.VideoQualityDelayMode;
|
||||
import yy.data.VideoRatioAttr;
|
||||
|
||||
public class ConfigVideo
|
||||
{
|
||||
public static function setPublishVideo_320x240_Tcp():Object
|
||||
{
|
||||
|
||||
var result:Object;
|
||||
var retCode:int=0;
|
||||
result = YY.instance.video.setProperty(VideoConfigAttr.CUR_BITRATE_LD_PID, 400 * 1000);
|
||||
if (result.ret != 0)
|
||||
retCode=result.ret;
|
||||
|
||||
result=YY.instance.video.setProperty(VideoConfigAttr.MIN_BITRATE_LD_PID, 300 * 1000);
|
||||
if (result.ret != 0)
|
||||
retCode=result.ret;
|
||||
|
||||
result=YY.instance.video.setProperty(VideoConfigAttr.MAX_BITRATE_LD_PID, 500 * 1000);
|
||||
if (result.ret != 0)
|
||||
retCode=result.ret;
|
||||
|
||||
result=YY.instance.video.setProperty(VideoConfigAttr.TOTAL_BIT_RATE_PID, 700 * 1000);
|
||||
if (result.ret != 0)
|
||||
retCode=result.ret;
|
||||
|
||||
result=YY.instance.video.setProperty(VideoConfigAttr.PLUGIN_PWP_SWITCH_PID, 1);
|
||||
if (result.ret != 0)
|
||||
retCode=result.ret;
|
||||
|
||||
result=YY.instance.video.setProperty(VideoConfigAttr.RESOLUTION_PID, VideoRatioAttr.RATIO_TRY_320x240);
|
||||
if (result.ret != 0)
|
||||
retCode=result.ret;
|
||||
|
||||
result=YY.instance.video.setProperty(VideoConfigAttr.ENC_PICTURE_RATIO_PID, VideoPictureRatioAttr.RESOLUTION_RATIO_4x3);
|
||||
if (result.ret != 0)
|
||||
retCode=result.ret;
|
||||
|
||||
|
||||
result=YY.instance.video.setProperty(VideoConfigAttr.QUALITY_DELAY_MODE_PID, VideoQualityDelayMode.ZORO_DELAY_MODE);
|
||||
if (result.ret != 0)
|
||||
retCode=result.ret;
|
||||
|
||||
|
||||
result= YY.instance.video.setProperty(VideoConfigAttr.FRAME_RATE_PID, 2);
|
||||
//result= YY.instance.video.setProperty(VideoConfigAttr.FRAME_RATE_PID, 2);
|
||||
if (result.ret != 0)
|
||||
retCode=result.ret;
|
||||
|
||||
result=YY.instance.video.setProperty(VideoConfigAttr.SMOOTH_VIDEO_UPLOAD,1);
|
||||
if (result.ret != 0)
|
||||
retCode=result.ret;
|
||||
|
||||
result=YY.instance.video.setProperty(VideoConfigAttr.LOW_CPU_COST_TUNE_PID, 1);
|
||||
|
||||
if (result.ret != 0)
|
||||
retCode=result.ret;
|
||||
|
||||
return {ret: retCode};
|
||||
}
|
||||
public static function setPublishVideo_480x360_Tcp():Object
|
||||
{
|
||||
|
||||
var result:Object;
|
||||
var retCode:int=0;
|
||||
result = YY.instance.video.setProperty(VideoConfigAttr.CUR_BITRATE_LD_PID, 400 * 1000);
|
||||
if (result.ret != 0)
|
||||
retCode=result.ret;
|
||||
|
||||
result=YY.instance.video.setProperty(VideoConfigAttr.MIN_BITRATE_LD_PID, 300 * 1000);
|
||||
if (result.ret != 0)
|
||||
retCode=result.ret;
|
||||
|
||||
result=YY.instance.video.setProperty(VideoConfigAttr.MAX_BITRATE_LD_PID, 500 * 1000);
|
||||
if (result.ret != 0)
|
||||
retCode=result.ret;
|
||||
|
||||
result=YY.instance.video.setProperty(VideoConfigAttr.TOTAL_BIT_RATE_PID, 700 * 1000);
|
||||
if (result.ret != 0)
|
||||
retCode=result.ret;
|
||||
|
||||
result=YY.instance.video.setProperty(VideoConfigAttr.PLUGIN_PWP_SWITCH_PID, 1);
|
||||
if (result.ret != 0)
|
||||
retCode=result.ret;
|
||||
|
||||
result=YY.instance.video.setProperty(VideoConfigAttr.RESOLUTION_PID, VideoRatioAttr.RATIO_TRY_480x360);
|
||||
if (result.ret != 0)
|
||||
retCode=result.ret;
|
||||
|
||||
result=YY.instance.video.setProperty(VideoConfigAttr.ENC_PICTURE_RATIO_PID, VideoPictureRatioAttr.RESOLUTION_RATIO_4x3);
|
||||
if (result.ret != 0)
|
||||
retCode=result.ret;
|
||||
|
||||
|
||||
result=YY.instance.video.setProperty(VideoConfigAttr.QUALITY_DELAY_MODE_PID, VideoQualityDelayMode.ZORO_DELAY_MODE);
|
||||
if (result.ret != 0)
|
||||
retCode=result.ret;
|
||||
|
||||
|
||||
result= YY.instance.video.setProperty(VideoConfigAttr.FRAME_RATE_PID, 2);
|
||||
if (result.ret != 0)
|
||||
retCode=result.ret;
|
||||
|
||||
result=YY.instance.video.setProperty(VideoConfigAttr.SMOOTH_VIDEO_UPLOAD, 1);
|
||||
if (result.ret != 0)
|
||||
retCode=result.ret;
|
||||
|
||||
result=YY.instance.video.setProperty(VideoConfigAttr.LOW_CPU_COST_TUNE_PID, 1);
|
||||
|
||||
if (result.ret != 0)
|
||||
retCode=result.ret;
|
||||
|
||||
return {ret: retCode};
|
||||
}
|
||||
public static function configEncode():void
|
||||
{
|
||||
var config:Object = {};
|
||||
config[75] = "keyint=30:min-keyint=30:scenecut=40:bframes=2:b-adapt=1:b-pyramid=none:threads=2:sliced-threads=0:ref=2:subme=6:me=hex:analyse=i4x4,i8x8,p8x8,b8x8:direct=spatial:weightp=1:weightb=1:8x8dct=1:cabac=1:deblock=0,0:psy=0:trellis=1:aq-mode=1:rc-lookahead=0:sync-lookahead=0:mbtree=0:force-cfr=0:";
|
||||
//config[75] = "keyint=100:min-keyint=25:scenecut=40:bframes=2:b-adapt=1:b-pyramid=none:threads=2:sliced-threads=0:ref=2:subme=6:me=hex:analyse=i4x4,i8x8,p8x8,b8x8:direct=spatial:weightp=1:weightb=1:8x8dct=1:cabac=1:deblock=0,0:psy=0:trellis=1:aq-mode=1:rc-lookahead=0:sync-lookahead=0:mbtree=0:force-cfr=0";
|
||||
//config[75] = "keyint=100:min-keyint=25:scenecut=40:bframes=2:b-adapt=1:b-pyramid=none:threads=2:sliced-threads=0:ref=2:subme=9:me=hex:analyse=i4x4,i8x8,p8x8,b8x8:direct=spatial:weightp=2:weightb=2:8x8dct=1:cabac=1:deblock=0,0:psy=0:trellis=1:aq-mode=1:rc-lookahead=60:sync-lookahead=0:mbtree=0:force-cfr=0";
|
||||
var res :Object = YY.instance.video.SetPluginConfigString(config);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user