polyv.vue 2.4 KB

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