polyv.vue 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. // this.detail = detail
  67. // // 设置mode为live的videoOption
  68. // // this.setLiveOption();
  69. // if (detail.isPPT) {
  70. // chat.on(chat.events.SLICESTART, () => {
  71. // // 开始直播
  72. // });
  73. // } else {
  74. // plv.api.getOrdinaryLiveStatus(detail.stream);
  75. // }
  76. });
  77. console.log(this.$refs.player)
  78. },
  79. onUnload() {
  80. plv.destroy();
  81. }
  82. };
  83. </script>
  84. <style scoped lang="scss">
  85. .plv-mp-demo-page {
  86. height:500rpx;
  87. }
  88. </style>