lookShipin.vue 3.1 KB

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