APICloud开发者进阶之路 | qiniuLive 连麦流程介绍

  • 日期:08-03
  • 点击:(1660)


本文来自APICloud官方论坛

qiniuLive封装了Seven Bull Live云服务平台的移动开放SDK。该模块包括两部分:视频流捕获和视频流播放。

iOS连小麦流程图:

c5607a57109e4a95bed96404afbcb53e

Android甚至小麦流程图:

1aaa80be1d5b4dfbbe1e273d0387d3d3

以下部分代码仅供参考 -

你好APP

体{

填充顶部: 760px;

}

按钮{

保证金: 10px;

}

锚定操作

initStreamingEnv - setStreamingProfile

startStream

configConference

startConference

子锚操作

initStreamingEnv - setStreamingProfile

startStream

configConference

startConference

播放

fninitPMediaPlayer

Fnstart

Var room_name,user_id,roomToken;

Var qiniuLive;

Apiready=function(){

qiniuLive=api.require('qiniuLive');

qiniuLive.initStreamingEnv(函数(RET){

如果(ret.status){

Console.log('initStreamingEnv的成功'+ JSON.stringify(ret));

qiniuLive.addRtcStateDidChangeListener(函数(RET){

Console.log('addRtcStateDidChangeListener ---'+ JSON.stringify(ret));

如果(ret.state=='inited'){

如果(api.systemType=='ios'){

fnconfigConference();

//fnstartConference();

}

}

});

qiniuLive.addEventListener({//流状态已更改事件

名称:'streamStatus'

},function(ret){

Console.log('streamStatus ---'+ JSON.stringify(ret));

如果(ret.streamStatus==17){//Android适用

fnconfigConference();

}

如果(ret.streamStatus==8){

}

});

qiniuLive.addRoomOIListener(函数(RET){

Console.log('进出房间'+ JSON.stringify(ret));

如果(ret.eventType=='didJoin'){

提醒(ret.userID +'进入房间')

}

});

qiniuLive.addRtcDidFailListener(函数(RET){

Console.log('错误回调addRtcDidFailListener监听器'+ JSON.stringify(ret));

});

}

});

};

//配置实时流参数以初始化推送流预览区域

函数fnsetStreamingProfile(pkuid){

//$api.setStorage('uid',pkuid);

qiniuLive.setStreamingProfile({

Rect: {

x: 0,

y: 0,

w: parseInt(api.frameWidth),

h: parseInt(api.frameWidth)

},

remoteWindowRect: [{

x: parseInt(api.frameWidth/2),

y: 0,

w: parseInt(api.frameWidth/2),

h: parseInt(api.frameHeight/2)

}],

pushUrl:''+ pkuid,//填写你自己的推送地址

videoCapture: {

videoFrameRate: 30,

sessionPreset:'100x100',

previewMirrorFrontFacing:是,

previewMirrorRearFacing: false,

streamMirrorFrontFacing: false,

streamMirrorRearFacing: false,

videoOrientation:' portrait',

cameraPosition:'front'

},

previewSetting: {

previewSizeLevel:'small',//字符类型;相机预览尺寸级别

//值范围:小,中,大

previewSizeRatio:'contio_4_3'//字符类型;相机预览尺寸比//这会改变局部比例吗?

//值范围:ratio_4_3,ratio_16_9

},

videoStream: {

videoSize: {

宽度: 960,

高度: 640

},

videoQuality:'low1'

},

localWinPosition: {

x: 0,

y: 0,

w: 480,

h: 640

},

encodeOritation:'landscape',

面对: {

美化:错误,

setBeautify: 0,

setWhiten: 0,

setRedden: 0

},

audioQuality:'medium',

continuousFocus: false,

fixedOn: api.frameName,

修正了: true

},function(ret){

如果(ret.status){

Console.log('setStreamingProfileSuccess'+ JSON.stringify(ret));

如果(api.systemType=='ios'){

Console.log('ios -----'+'setWithServerRegion');

qiniuLive.setWithServerRegion({

serverRegionID: 0

});

}

}

});

}

//开始推送

函数fnstartStream(){

qiniuLive.startStream(函数(RET){

如果(ret.status==true){

Console.log('推动成功');

}否则{

//start_stream();

Console.log('推送失败');

}

});

}

//配置连小麦

函数fnconfigConference(x){

qiniuLive.configConference({

videoEncodingSizeRatio:'contio_4_3',

videoEncodingSize: 480,

videoBitrateRange: {

从: 100 * 1000,

至: 300 * 1000

},

Fps: 20,

mixVideoSize: {//默认值与setStream接口的videoStream - > videoSize参数一致

宽度: 640,

高度: 480

},

localVideoRect: {

x: x,//(可选)数字类型; x坐标;默认值:0

y: 0,//(可选)数字类型; y坐标;默认值:0

宽度: 320,

高度: 480,

//width: parseInt(api.frameWidth),

//height: parseInt(api.frameHeight)

},

mixOverlayRectArray: [{//控制观众的屏幕

x: 480,

y: 0,

w: 480,

h: 640

}

//,{

//x: 120,

//y: 120,

//w: 120,

//h: 120

//}

],

rejoinTimes: 3,

connetTimeout: 5000

},function(ret){

如果(ret.status){

Console.log('configConference success'+ JSON.stringify(ret));

fnstartStream();

}否则{

Console.log('configConference failed');

}

});

}

//从服务器获取实时房间号码,令牌,然后开始连接到小麦

函数fnstartConference(uid){

Api.ajax({

键入:'get',

Url:''+ uid //填写您自己的服务器接口地址

},function(ret){

Var room=ret.content;

Room_name=room.room_name;

roomToken=room.roomToken;

qiniuLive.startConference({

userId: uid,

roomName: room_name,

roomToken: roomToken

},function(ret,err){

如果(ret){

Console.log('startConference ---'+ JSON.stringify(ret));

}否则{

Console.log('startConference ---'+ JSON.stringify(err));

}

});

})

}

//停止推动,甚至停止小麦

函数stopStearm(){

qiniuLive.stopStream(函数(RET){

警报('已停止推');

});

qiniuLive.stopConference(函数(RET){

//alert('End Lian Mai');

});

}

//初始化播放器,播放器调用

函数fninitPMediaPlayer(){

qiniuLive.initPMediaPlayer({

Rect: {

x: 0,

y: 0,

w: 320,

h: 480

},

dataUrl:'',//填写你自己的拉地址

编解码器: 0,

prepareTimeout: 10000,

readTimeout: 10000,

isLiveStream:是,

isDelayOptimization:是,

cacheBufferDuration: 2000,

maxCacheBufferDuration: 4000,

fixedOn: api.frameName,

修正了: true

},function(ret){

警报(JSON.stringify(保留));

});

}

//开始播放,播放器调用

函数fnstart(){

qiniuLive.start(函数(RET){

警报(JSON.stringify(保留));

});

}

复制代码