lookShipin3.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. <template>
  2. <view id="player-con"></view>
  3. </template>
  4. <script setup module="openlayers" lang="renderjs" >
  5. import {
  6. videoPolicy,
  7. getVideoAuth,
  8. getVideoRefresh
  9. } from "@/api/shipin.js"
  10. import {
  11. ref,
  12. onMounted,
  13. reactive
  14. } from "vue"
  15. const loadWebPlayerSDK = async () => {
  16. return new Promise((resolve, reject) => {
  17. const s_tag = document.createElement('script'); // 引入播放器js
  18. s_tag.type = 'text/javascript';
  19. s_tag.src = 'https://g.alicdn.com/de/prismplayer/2.9.6/aliplayer-min.js';
  20. s_tag.charset = 'utf-8';
  21. s_tag.onload = () => {
  22. resolve();
  23. }
  24. document.body.appendChild(s_tag);
  25. const l_tag = document.createElement('link'); // 引入播放器css
  26. l_tag.rel = 'stylesheet';
  27. l_tag.href = 'https://g.alicdn.com/de/prismplayer/2.9.6/skins/default/aliplayer-min.css';
  28. document.body.appendChild(l_tag);
  29. });
  30. }
  31. let videoUrl = 'https://qiniu-web-assets.dcloud.net.cn/unidoc/zh/2minute-demo.mp4'
  32. let pageData = reactive({
  33. type: '',
  34. partUrl: '',
  35. downloadUrl: '',
  36. videoId: '',
  37. uploadAddress: '',
  38. uploadAuth: '',
  39. signature: '',
  40. playauth: '',
  41. })
  42. onMounted(()=>{
  43. console.log(111)
  44. loadWebPlayerSDK().then(() => {
  45. // 如果需要使用自定义组件,打开以下注释
  46. // this.loadComponent().then(() => {
  47. let player = new Aliplayer({
  48. id: "url-player-test",
  49. source: "//player.alicdn.com/video/aliyunmedia.mp4",
  50. width: "100%",
  51. height: "100%",
  52. }, function (player) {
  53. });
  54. player.one('canplay', function () {
  55. console.log('canplay', player.tag);
  56. player.tag.play();
  57. });
  58. // }).catch((e) => { console.log("加载组件失败", e) })
  59. }).catch((e) => {
  60. console.log("加载播放器SDK失败", e);
  61. });
  62. })
  63. // onMounted(() => {
  64. // loadWebPlayerSDK().then(() => {
  65. // getPlayAuth()
  66. // }).catch((e) => {
  67. // console.log("加载播放器SDK失败", e);
  68. // });
  69. // })
  70. // function getVideoId(){
  71. // let req ={
  72. // fileName:videoUrl,
  73. // title:"测试视频"
  74. // }
  75. // videoPolicy(req).then(res=>{
  76. // pageData.videoId = res.data.videoId
  77. // getPlayAuth()
  78. // })
  79. // }
  80. function getPlayAuth() {
  81. let req = {
  82. videoId: 'b997f16cb9cb474cb93526cff77d8801'
  83. }
  84. getVideoAuth(req).then(res => {
  85. pageData.playauth = res.data
  86. playAli()
  87. })
  88. }
  89. function playAli() {
  90. let configData = {
  91. "id": "player-con",
  92. "vid": 'b997f16cb9cb474cb93526cff77d8801',
  93. "playauth": pageData.playauth,
  94. "qualitySort": "asc",
  95. "format": "m3u8",
  96. "mediaType": "video",
  97. "encryptType": 1,
  98. "width": '100%',
  99. progressMarkers: [{
  100. offset: 30,
  101. isCustomized: true,
  102. coverUrl: 'https://alivc-demo-vod.aliyuncs.com/image/cover/9A3F562E595E4764AD1DD546FA52C6E5-6-2.png',
  103. title: 'test title',
  104. describe: 'test string',
  105. }, {
  106. offset: 50,
  107. isCustomized: true,
  108. coverUrl: 'https://alivc-demo-vod.aliyuncs.com/image/cover/1E7F402241CD4C0F94AD2BBB5CCC3EC7-6-2.png',
  109. title: 'test title',
  110. describe: 'test string',
  111. }, {
  112. offset: 150,
  113. isCustomized: true,
  114. coverUrl: 'https://alivc-demo-vod.aliyuncs.com/image/cover/553AEA01161342C8A2B1756E83B69B5B-6-2.png',
  115. title: 'test title',
  116. describe: 'test string',
  117. }, {
  118. offset: 120,
  119. isCustomized: true,
  120. coverUrl: 'https://alivc-demo-vod.aliyuncs.com/image/cover/553AEA01161342C8A2B1756E83B69B5B-6-2.png',
  121. title: 'test title',
  122. describe: 'test string',
  123. }],
  124. "height": '500px',
  125. "autoplay": false,
  126. "isLive": false,
  127. "rePlay": false,
  128. "playsinline": true,
  129. "preload": false,
  130. "controlBarVisibility": "hover",
  131. "useH5Prism": true
  132. }
  133. var player = new Aliplayer(configData, function(player) {
  134. console.log('The player is created.')
  135. });
  136. }
  137. </script>