broadcast.nvue 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <template>
  2. <view>
  3. <live-pusher id="livePusher" :url="url" :enable-camera="enableCamera" mode="FHD"></live-pusher>
  4. <button @click="startLive">开始推流(开始直播)</button>
  5. <button @click="stopLive">结束推流</button>
  6. </view>
  7. </template>
  8. <script>
  9. export default {
  10. data() {
  11. return {
  12. url: 'rtmp://push.zthymaoyi.com/yiliangyiyun/yiliangyiyun?auth_key=1617364201-0-0-3f3d8038dc37a0232dd7ba8e6586fd4d',
  13. enableCamera: true,
  14. context: null
  15. };
  16. },
  17. onReady() {
  18. this.context = uni.createLivePusherContext('livePusher', this);
  19. console.log(this.context)
  20. this.context.switchCamera() // 摄像头切换(切换为后置)
  21. this.context.startPreview() // 摄像头预览 (不加会黑屏)
  22. },
  23. methods: {
  24. startLive() {
  25. this.context.start({
  26. success: a => {
  27. console.log('livePusher.start:' + JSON.stringify(a));
  28. }
  29. });
  30. },
  31. stopLive() {
  32. this.context.stop({
  33. success: a => {
  34. console.log(JSON.stringify(a));
  35. }
  36. });
  37. }
  38. }
  39. };
  40. </script>