TUILiveKit 产品动态
云直播推拉流 SDK 产品动态

<script src="https://video.sdk.qcloudecdn.com/web/TXLivePusher-2.1.0.min.js" charset="utf-8"></script>
<div id="id_local_video" style="width:100%;height:500px;display:flex;align-items:center;justify-content:center;"></div>
TXLivePusher 生成 SDK 实例,后续操作都是通过实例完成。var livePusher = new TXLivePusher();
livePusher.setRenderView('id_local_video');
setRenderView生成的 video 元素默认有声音,如果需要静音的话,可以直接获取 video 元素进行操作。document.getElementById('id_local_video').getElementsByTagName('video')[0].muted = true;
// 设置视频质量livePusher.setVideoQuality('720p');// 设置音频质量livePusher.setAudioQuality('standard');// 自定义设置帧率livePusher.setProperty('setVideoFPS', 25);
// 打开摄像头livePusher.startCamera();// 打开麦克风livePusher.startMicrophone();
rtmp://替换成webrtc://即可。livePusher.startPush('webrtc://domain/AppName/StreamName?txSecret=xxx&txTime=xxx');
var hasVideo = false;var hasAudio = false;var isPush = false;livePusher.setObserver({onCaptureFirstAudioFrame: function() {hasAudio = true;if (hasVideo && !isPush) {isPush = true;livePusher.startPush('webrtc://domain/AppName/StreamName?txSecret=xxx&txTime=xxx');}},onCaptureFirstVideoFrame: function() {hasVideo = true;if (hasAudio && !isPush) {isPush = true;livePusher.startPush('webrtc://domain/AppName/StreamName?txSecret=xxx&txTime=xxx');}}});
livePusher.stopPush();
// 关闭摄像头livePusher.stopCamera();// 关闭麦克风livePusher.stopMicrophone();
TXLivePusher.checkSupport().then(function(data) {// 是否支持WebRTCif (data.isWebRTCSupported) {console.log('WebRTC Support');} else {console.log('WebRTC Not Support');}// 是否支持H264编码if (data.isH264EncodeSupported) {console.log('H264 Encode Support');} else {console.log('H264 Encode Not Support');}});
livePusher.setObserver({// 推流警告信息onWarning: function(code, msg) {console.log(code, msg);},// 推流连接状态onPushStatusUpdate: function(status, msg) {console.log(status, msg);},// 推流统计数据onStatisticsUpdate: function(data) {console.log('video fps is ' + data.video.framesPerSecond);}});
var deviceManager = livePusher.getDeviceManager();// 获取设备列表deviceManager.getDevicesList().then(function(data) {data.forEach(function(device) {console.log(device.deviceId, device.deviceName);});});// 切换摄像头设备deviceManager.switchCamera('camera_device_id');
文档反馈