<template>
<view>
<live-pusher id="livePusher" :url="url" :enable-camera="enableCamera" mode="FHD"></live-pusher>
<button @click="startLive">开始推流(开始直播)</button>
<button @click="stopLive">结束推流</button>
</view>
</template>
<script>
export default {
data() {
return {
url: 'rtmp://192.168.1.11:1935/live/621FD133-889D-1707-CF0E-83A8A715D412',
enableCamera: true,
context: null
};
},
onReady() {
this.context = uni.createLivePusherContext('livePusher', this);
this.context.switchCamera() // 摄像头切换(切换为后置)
this.context.startPreview() // 摄像头预览 (不加会黑屏)
},
methods: {
startLive() {
this.context.start({
success: a => {
console.log('livePusher.start:' + JSON.stringify(a));
}
});
},
stopLive() {
this.context.stop({
success: a => {
console.log(JSON.stringify(a));
}
});
}
}
}
</script>
<style>
video {
width: 690 rpx;
}
</style>