aliyun-video.vue 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <template>
  2. <view :class="loadingClass" v-if="!url">{{ loadingText }}</view>
  3. <block v-else>
  4. <!-- #ifdef MP-WEIXIN -->
  5. <video :src="url"></video>
  6. <!-- #endif -->
  7. <!-- #ifdef H5 || WEB || MP-GONGZHONGHAO -->
  8. <div id="mui-player"></div>
  9. <!-- #endif -->
  10. </block>
  11. </template>
  12. <script>
  13. import { nextTick } from "vue";
  14. import { handle, request } from "@kasite/uni-app-base";
  15. import { REQUEST_CONFIG } from "@kasite/uni-app-base/config";
  16. import "mui-player/dist/mui-player.min.css";
  17. import MuiPlayer from "mui-player";
  18. import Hls from "hls.js";
  19. export default {
  20. props: {
  21. // 视频ID
  22. videoId: {
  23. type: [String, null],
  24. default: null,
  25. },
  26. },
  27. data() {
  28. return {
  29. url: "",
  30. loadingText: "视频解码中",
  31. loadingClass: "aliyun-video-loading-text",
  32. };
  33. },
  34. methods: {
  35. async doPost(url, data, options) {
  36. let resp = handle.promistHandleNew(await request.doPost(url, data, options));
  37. return handle.catchPromiseNew(resp, () => resp, options);
  38. },
  39. async getVideoUrlByIdasync(id) {
  40. if (!id) return;
  41. const { resp } = await this.doPost(`${REQUEST_CONFIG.BASE_URL}wsgw/article/video/GetVideoUrl/callApiJSON.do`, { ID: id });
  42. const url = resp && resp.length ? resp[0].Url : "";
  43. if (!url) {
  44. this.loadingClass = "aliyun-video-loading-fail-text";
  45. this.loadingText = "视频未完成解码,请刷新页面或稍后再试";
  46. } else {
  47. this.url = url;
  48. //#ifdef H5 || WEB || MP-GONGZHONGHAO
  49. nextTick(() => this.mpPlayerInit());
  50. //#endif
  51. }
  52. },
  53. mpPlayerInit() {
  54. const dom = this.$el;
  55. var mp = new MuiPlayer({
  56. container: dom,
  57. src: this.url,
  58. parse: {
  59. type: "hls",
  60. loader: Hls,
  61. config: {
  62. // hls config to:https://github.com/video-dev/hls.js/blob/HEAD/docs/API.md#fine-tuning
  63. debug: false,
  64. },
  65. },
  66. // pageHead: false,
  67. height: "220px",
  68. });
  69. },
  70. },
  71. mounted() {
  72. this.getVideoUrlByIdasync(this.videoId);
  73. },
  74. };
  75. </script>
  76. <style>
  77. .aliyun-video-loading-fail-text {
  78. color: red;
  79. }
  80. .aliyun-video-loading-text::after {
  81. animation: aliyun-video-loading-dots 2s linear infinite;
  82. content: "";
  83. }
  84. @keyframes aliyun-video-loading-dots {
  85. 0% {
  86. content: ".";
  87. }
  88. 30% {
  89. content: "..";
  90. }
  91. 60% {
  92. content: "...";
  93. }
  94. 90% {
  95. content: "";
  96. }
  97. }
  98. </style>