lookShipin.vue 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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. "encryptType": 1,
  79. // "playConfig": {
  80. // "EncryptType": 'AliyunVoDEncryption'
  81. // },
  82. "qualitySort": "asc",
  83. "format": "m3u8",
  84. "mediaType": "video",
  85. "encryptType": 1,
  86. "progressMarkers": [{
  87. offset: 30,
  88. isCustomized: true,
  89. coverUrl: 'https://alivc-demo-vod.aliyuncs.com/image/cover/9A3F562E595E4764AD1DD546FA52C6E5-6-2.png',
  90. title: 'test title',
  91. describe: 'test string',
  92. }, {
  93. offset: 150,
  94. isCustomized: true,
  95. coverUrl: 'https://alivc-demo-vod.aliyuncs.com/image/cover/1E7F402241CD4C0F94AD2BBB5CCC3EC7-6-2.png',
  96. title: 'test title',
  97. describe: 'test string',
  98. }, {
  99. offset: 250,
  100. isCustomized: true,
  101. coverUrl: 'https://alivc-demo-vod.aliyuncs.com/image/cover/553AEA01161342C8A2B1756E83B69B5B-6-2.png',
  102. title: 'test title',
  103. describe: 'test string',
  104. }, {
  105. offset: 550,
  106. isCustomized: true,
  107. coverUrl: 'https://alivc-demo-vod.aliyuncs.com/image/cover/553AEA01161342C8A2B1756E83B69B5B-6-2.png',
  108. title: 'test title',
  109. describe: 'test string',
  110. }, {
  111. offset: 320,
  112. isCustomized: true,
  113. coverUrl: 'https://alivc-demo-vod.aliyuncs.com/image/cover/553AEA01161342C8A2B1756E83B69B5B-6-2.png',
  114. title: 'test title',
  115. describe: 'test string',
  116. }],
  117. "width": '100%',
  118. "height": '500px',
  119. "autoplay": false,
  120. "isLive": false,
  121. "rePlay": false,
  122. "playsinline": true,
  123. "preload": false,
  124. "controlBarVisibility": "hover",
  125. "useH5Prism": true
  126. }, function(player) {});
  127. this.player = player;
  128. player.one('canplay', function() {
  129. console.log('canplay', this.player.tag);
  130. player.tag.play();
  131. });
  132. },
  133. //监听获取播放凭证的方法
  134. checkValue() {
  135. console.log(this.videoId, this.authId, "1111888888")
  136. if (!this.videoData.playAuth) {
  137. setTimeout(() => {
  138. this.checkValue();
  139. }, 1000);
  140. } else {
  141. this.getLive();
  142. }
  143. },
  144. loadWebPlayerSDK() {
  145. return new Promise((resolve, reject) => {
  146. const s_tag = document.createElement('script'); // 引入播放器js
  147. s_tag.type = 'text/javascript';
  148. s_tag.src = 'https://g.alicdn.com/de/prismplayer/2.9.6/aliplayer-min.js';
  149. s_tag.charset = 'utf-8';
  150. s_tag.onload = () => {
  151. // this.checkValue();
  152. resolve();
  153. }
  154. document.body.appendChild(s_tag);
  155. const l_tag = document.createElement('link'); // 引入播放器css
  156. l_tag.rel = 'stylesheet';
  157. l_tag.href =
  158. 'https://g.alicdn.com/de/prismplayer/2.9.6/skins/default/aliplayer-min.css';
  159. document.body.appendChild(l_tag);
  160. });
  161. },
  162. }
  163. }
  164. </script>