polyv.vue 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <template>
  2. <view class="plv-mp-demo-page">
  3. <player
  4. class="plv-mp-demo-player"
  5. :videoOption="videoOption"
  6. />
  7. </view>
  8. </template>
  9. <script>
  10. import plv from '../../wxcomponents/polyv-sdk/index';
  11. export default {
  12. data() {
  13. return {
  14. videoOption:{
  15. mode: 'live',
  16. uid: 'egsxlptzdq',
  17. cid: '2553128',
  18. openId: 'oQ5eX5BCtSjkE1ct8CzvxGWgh0hQ',
  19. isAutoChange: false,
  20. forceVideo: false,
  21. },
  22. detail: {},
  23. };
  24. },
  25. mounted() {},
  26. methods: {
  27. setLiveOption(status) {
  28. const { userId, channelId, recordFileSimpleModel, playbackEnabled } = this.detail;
  29. const playRecordFile = playbackEnabled && recordFileSimpleModel && status === 'end';
  30. this.videoOption = {
  31. mode: 'live',
  32. uid: userId,
  33. cid: channelId,
  34. isAutoChange: false,
  35. forceVideo: false,
  36. vodsrc: playRecordFile ? recordFileSimpleModel.mp4 || recordFileSimpleModel.m3u8 : '',
  37. liveMode: playRecordFile ? 2 : 1,
  38. }
  39. }
  40. },
  41. onLoad(options) {
  42. options.mode = 'live';
  43. options.forceVideo = false;
  44. options.channelId = '2553128'; // 频道ID
  45. options.openId = 'oQ5eX5BCtSjkE1ct8CzvxGWgh0hQ'; // 用户openId
  46. // userName: ''; // 用户名
  47. // avatarUrl: ''; // 用户头像
  48. options.userId = 'egsxlptzdq' // 2.0.0及以上版本的demo需要使用 userId 设置学员唯一id
  49. plv.init(options)
  50. .then(({ detail, chat }) => {
  51. console.log(9999)
  52. this.detail = detail
  53. // 设置mode为live的videoOption
  54. // this.setLiveOption();
  55. if (detail.isPPT) {
  56. chat.on(chat.events.SLICESTART, () => {
  57. // 开始直播
  58. });
  59. } else {
  60. plv.api.getOrdinaryLiveStatus(detail.stream);
  61. }
  62. });
  63. console.log(this.$refs.plv)
  64. },
  65. onUnload() {
  66. plv.destroy();
  67. }
  68. };
  69. </script>
  70. <style scoped lang="scss">
  71. .plv-mp-demo-page {
  72. height:500rpx;
  73. }
  74. </style>