148 lines
4.1 KiB
Vue
148 lines
4.1 KiB
Vue
<template>
|
|
<view>
|
|
<video :is-live="true" id="myVideo" :src="videoSrc" :autoplay="true"></video>
|
|
<live-pusher id="livePusher" ref="livePusher" class="livePusher" url="rtmp://25.18.122.148:9605/voice_in/aa" mode="SD" :muted="true" :enable-camera="false" :auto-focus="true" :beauty="1" whiteness="2" aspect="9:16" @statechange="statechange" @netstatus="netstatus" @error="error"></live-pusher>
|
|
|
|
<view class="btn" @click="prepare"><text>预热</text></view>
|
|
<view class="btn" @click="start"><text>开始推流</text></view>
|
|
<view class="btn" @click="pause"><text>暂停推流</text></view>
|
|
<view class="btn" @click="resume"><text>恢复推流</text></view>
|
|
<view class="btn" @click="stop"><text>停止推流</text></view>
|
|
<view class="btn" @click="snapshot"><text>快照</text></view>
|
|
<view class="btn" @click="startPreview"><text>开启摄像头预览</text></view>
|
|
<view class="btn" @click="stopPreview"><text>关闭摄像头预览</text></view>
|
|
<view class="btn" @click="switchCamera"><text>切换摄像头</text></view>
|
|
</view>
|
|
</template>
|
|
|
|
<script>
|
|
import { prepareApi } from '@/api/talk.js'
|
|
var pusher
|
|
export default {
|
|
data() {
|
|
return {
|
|
context: null,
|
|
baseName: 'aaa'
|
|
}
|
|
},
|
|
computed: {
|
|
videoSrc() {
|
|
return 'rtmp://rtmp.home.tymas.cn:1935/voice_in/' + this.baseName
|
|
}
|
|
},
|
|
onReady() {
|
|
const videoContext = uni.createVideoContext('myVideo')
|
|
videoContext.setVolume(1.0)
|
|
// 注意:需要在onReady中 或 onLoad 延时
|
|
// pusher = uni.createLivePusherContext('livePusher', this)
|
|
// console.log(pusher)
|
|
},
|
|
methods: {
|
|
statechange(e) {
|
|
console.log('statechange:', e, JSON.stringify(e))
|
|
},
|
|
netstatus(e) {
|
|
console.log('netstatus:' + JSON.stringify(e))
|
|
},
|
|
error(e) {
|
|
console.log('error:' + JSON.stringify(e))
|
|
},
|
|
start: function () {
|
|
console.log('statechange:', pusher.start)
|
|
pusher.start({
|
|
success: a => {
|
|
console.log('livePusher.start:' + JSON.stringify(a))
|
|
}
|
|
})
|
|
},
|
|
prepare: function () {
|
|
this.initPusher()
|
|
// prepareApi(this.baseName)
|
|
// .then(res => {
|
|
// console.log(res)
|
|
// })
|
|
// .catch(err => {
|
|
// console.log(err)
|
|
// if (err === 'prepare') {
|
|
// this.initPusher()
|
|
// }
|
|
// })
|
|
},
|
|
close: function () {
|
|
pusher.close({
|
|
success: a => {
|
|
console.log('livePusher.close:' + JSON.stringify(a))
|
|
}
|
|
})
|
|
},
|
|
snapshot: function () {
|
|
pusher.snapshot({
|
|
success: e => {
|
|
console.log(JSON.stringify(e))
|
|
}
|
|
})
|
|
},
|
|
resume: function () {
|
|
pusher.resume({
|
|
success: a => {
|
|
console.log('livePusher.resume:' + JSON.stringify(a))
|
|
}
|
|
})
|
|
},
|
|
pause: function () {
|
|
pusher.pause({
|
|
success: a => {
|
|
console.log('livePusher.pause:' + JSON.stringify(a))
|
|
}
|
|
})
|
|
},
|
|
stop: function () {
|
|
pusher.stop({
|
|
success: a => {
|
|
console.log(JSON.stringify(a))
|
|
}
|
|
})
|
|
},
|
|
switchCamera: function () {
|
|
pusher.switchCamera({
|
|
success: a => {
|
|
console.log('livePusher.switchCamera:' + JSON.stringify(a))
|
|
}
|
|
})
|
|
},
|
|
startPreview: function () {
|
|
pusher.startPreview({
|
|
success: a => {
|
|
console.log('livePusher.startPreview:' + JSON.stringify(a))
|
|
}
|
|
})
|
|
},
|
|
stopPreview: function () {
|
|
pusher.stopPreview({
|
|
success: a => {
|
|
console.log('livePusher.stopPreview:' + JSON.stringify(a))
|
|
}
|
|
})
|
|
},
|
|
initPusher() {
|
|
pusher = new plus.video.LivePusher('pusher-box', {
|
|
url: 'rtmp://rtmp.home.tymas.cn:1935/voice_in/' + this.baseName,
|
|
'enable-camera': true
|
|
})
|
|
pusher.addEventListener('statechange', this.statechange)
|
|
pusher.addEventListener('netstatus', this.netstatus)
|
|
pusher.addEventListener('error', this.error)
|
|
console.log(pusher)
|
|
}
|
|
}
|
|
}
|
|
</script>
|
|
<style>
|
|
.btn {
|
|
width: 100%;
|
|
height: 80rpx;
|
|
background-color: #ccc;
|
|
margin-bottom: 5rpx;
|
|
}
|
|
</style>
|