123456789101112131415161718192021222324252627282930313233343536373839404142 |
- <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://push.zthymaoyi.com/yiliangyiyun/yiliangyiyun?auth_key=1617364201-0-0-3f3d8038dc37a0232dd7ba8e6586fd4d',
- enableCamera: true,
- context: null
- };
- },
- onReady() {
- this.context = uni.createLivePusherContext('livePusher', this);
- console.log(this.context)
- 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>
|