lookShipin.vue 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. <template>
  2. <view ref="videoContent" id="wgy-player-test" :playAuth="playAuth" :change:playAuth="renderScript.receiveMsg">
  3. </view>
  4. </template>
  5. <script>
  6. import {
  7. onLoad,
  8. onReady
  9. } from '@dcloudio/uni-app';
  10. import {
  11. videoPolicy,
  12. getVideoAuth,
  13. getVideoRefresh
  14. } from "@/api/shipin.js"
  15. export default {
  16. data() {
  17. return {
  18. options: {}, //上个页面获取的视频参数(视频id)
  19. playAuth: "", //播放凭证
  20. videoId: "", //阿里云视频id
  21. videoData: {
  22. playauth: '',
  23. videoId: 'b997f16cb9cb474cb93526cff77d8801',
  24. }, //阿里云视频其他参数
  25. }
  26. },
  27. methods: {
  28. getLive() {
  29. let req = {
  30. videoId: this.videoData.videoId
  31. }
  32. getVideoAuth(req).then(res => {
  33. this.playAuth = res.data
  34. // console.log(this.videoData)
  35. //this.playAli()
  36. })
  37. },
  38. },
  39. created() {
  40. console.log("getLive")
  41. this.getLive(); //获取播放凭证
  42. },
  43. }
  44. </script>
  45. <script module="renderScript" lang="renderjs">
  46. export default {
  47. mounted() {
  48. console.log("renderScript1")
  49. // 在适合的生命周期,通过script和link标签引入播放器sdk、css
  50. this.loadWebPlayerSDK()
  51. },
  52. data() {
  53. return {
  54. player: null,
  55. playAuth: '',
  56. }
  57. },
  58. methods: {
  59. receiveMsg(newValue, oldValue, ownerInstance, instance) {
  60. console.log('service层中的options发生变化')
  61. console.log('新值', newValue)
  62. console.log('旧值', oldValue)
  63. // ownerInstance和this.$ownerInstance一样,可用来向service层通信
  64. // instance和ownerInstance的区别是:
  65. // instance.$el指向的是触发事件的那个节点;ownerInstance.$el指向当前vue文件中的根节点;
  66. // instance的作用目前尚不明确,官方没有给出用法
  67. if (newValue) {
  68. this.playAuth = newValue
  69. this.playAli()
  70. }
  71. },
  72. playAli() {
  73. //配置播放器
  74. var player = new Aliplayer({
  75. id: "wgy-player-test",
  76. "vid": 'b997f16cb9cb474cb93526cff77d8801',
  77. "playauth": this.playAuth,
  78. // "playConfig": {
  79. // "EncryptType": 'AliyunVoDEncryption'
  80. // },
  81. "qualitySort": "asc",
  82. "format": "m3u8",
  83. "mediaType": "video",
  84. "encryptType": 1,
  85. "progressMarkers": [{
  86. offset: 30,
  87. isCustomized: true,
  88. coverUrl: 'https://alivc-demo-vod.aliyuncs.com/image/cover/9A3F562E595E4764AD1DD546FA52C6E5-6-2.png',
  89. title: 'test title',
  90. describe: 'test string',
  91. }, {
  92. offset: 150,
  93. isCustomized: true,
  94. coverUrl: 'https://alivc-demo-vod.aliyuncs.com/image/cover/1E7F402241CD4C0F94AD2BBB5CCC3EC7-6-2.png',
  95. title: 'test title',
  96. describe: 'test string',
  97. }, {
  98. offset: 250,
  99. isCustomized: true,
  100. coverUrl: 'https://alivc-demo-vod.aliyuncs.com/image/cover/553AEA01161342C8A2B1756E83B69B5B-6-2.png',
  101. title: 'test title',
  102. describe: 'test string',
  103. }, {
  104. offset: 550,
  105. isCustomized: true,
  106. coverUrl: 'https://alivc-demo-vod.aliyuncs.com/image/cover/553AEA01161342C8A2B1756E83B69B5B-6-2.png',
  107. title: 'test title',
  108. describe: 'test string',
  109. }, {
  110. offset: 320,
  111. isCustomized: true,
  112. coverUrl: 'https://alivc-demo-vod.aliyuncs.com/image/cover/553AEA01161342C8A2B1756E83B69B5B-6-2.png',
  113. title: 'test title',
  114. describe: 'test string',
  115. }],
  116. "width": '100%',
  117. "height": '500px',
  118. "autoplay": false,
  119. "isLive": false,
  120. "rePlay": false,
  121. "playsinline": true,
  122. "preload": false,
  123. "controlBarVisibility": "hover",
  124. "useH5Prism": true
  125. }, function(player) {});
  126. this.player = player;
  127. player.one('canplay', function() {
  128. console.log('canplay', this.player.tag);
  129. player.tag.play();
  130. });
  131. },
  132. //监听获取播放凭证的方法
  133. checkValue() {
  134. console.log(this.videoId, this.authId, "1111888888")
  135. if (!this.videoData.playAuth) {
  136. setTimeout(() => {
  137. this.checkValue();
  138. }, 1000);
  139. } else {
  140. this.getLive();
  141. }
  142. },
  143. loadWebPlayerSDK() {
  144. return new Promise((resolve, reject) => {
  145. const s_tag = document.createElement('script'); // 引入播放器js
  146. s_tag.type = 'text/javascript';
  147. s_tag.src = 'https://g.alicdn.com/de/prismplayer/2.9.6/aliplayer-min.js';
  148. s_tag.charset = 'utf-8';
  149. s_tag.onload = () => {
  150. // this.checkValue();
  151. resolve();
  152. }
  153. document.body.appendChild(s_tag);
  154. const l_tag = document.createElement('link'); // 引入播放器css
  155. l_tag.rel = 'stylesheet';
  156. l_tag.href =
  157. 'https://g.alicdn.com/de/prismplayer/2.9.6/skins/default/aliplayer-min.css';
  158. document.body.appendChild(l_tag);
  159. });
  160. },
  161. }
  162. }
  163. </script>