liveD.vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. <template>
  2. <div class="liveD" v-loading="loading">
  3. <van-nav-bar
  4. title="订单详情"
  5. class="van-nav-bar-my-fixed"
  6. left-arrow
  7. @click-left="onClickLeft"
  8. fixedfixed
  9. />
  10. <div class="page-main" style="padding-top: 44px">
  11. <!-- <div class="oDetail" > -->
  12. <video-player
  13. ref="videoPlayer"
  14. id="videoPlayer"
  15. style="width: 100%"
  16. :playsinline="true"
  17. :options="Options"
  18. />
  19. </div>
  20. </div>
  21. </template>
  22. <script>
  23. import asyncRequest from "@/apis/live/index";
  24. import resToken from "@/mixins/resToken";
  25. export default {
  26. mixins: [resToken],
  27. data() {
  28. return {
  29. Options: {},
  30. img: "",
  31. url: "",
  32. };
  33. },
  34. async created() {
  35. window.onresize = () => {
  36. this.getHeight();
  37. };
  38. this.id = this.$route.query.id ? this.$route.query.id : "0";
  39. this.initOPtions();
  40. await this.initData();
  41. },
  42. mounted() {
  43. this.$nextTick(() => {
  44. this.getHeight();
  45. });
  46. },
  47. methods: {
  48. getHeight() {
  49. console.log(this.$refs.videoPlayer);
  50. },
  51. onClickLeft() {
  52. window.history.back(-1);
  53. },
  54. async initData() {
  55. const res = await asyncRequest.detail({ id: this.id });
  56. if (res && res.code === 0) {
  57. const { video_url, video_img } = res.data;
  58. this.img = video_img;
  59. this.url = video_url;
  60. this.initOPtions();
  61. } else if (res && res.code >= 100 && res.code <= 104) {
  62. await this.logout();
  63. } else {
  64. this.show_title(res.msg);
  65. }
  66. },
  67. initOPtions() {
  68. this.Options = {
  69. autoplay: false, // 如果true,浏览器准备好时开始回放。
  70. muted: false, // 默认情况下将会消除任何音频。
  71. loop: false, // 导致视频一结束就重新开始。
  72. preload: "auto", // 建议浏览器在<video>加载元素后是否应该开始下载视频数据。auto浏览器选择最佳行为,立即开始加载视频(如果浏览器支持)
  73. language: "zh-CN",
  74. aspectRatio: "16:10", // 将播放器置于流畅模式,并在计算播放器的动态大小时使用该值。值应该代表一个比例 - 用冒号分隔的两个数字(例如"16:9"或"4:3")
  75. fluid: true, // 当true时,Video.js player将拥有流体大小。换句话说,它将按比例缩放以适应其容器。
  76. sources: [
  77. {
  78. type: "application/x-mpegURL", // 这里的种类支持很多种:基本视频格式、直播、流媒体等,具体可以参看git网址项目
  79. src: this.url, // 视频url地址
  80. poster: this.img, // 你的封面地址 // width: document.documentElement.clientWidth, //播放器宽度
  81. notSupportedMessage: "此视频暂无法播放,请稍后再试", // 允许覆盖Video.js无法播放媒体源时显示的默认信息。
  82. controlBar: {
  83. timeDivider: true,
  84. durationDisplay: true,
  85. remainingTimeDisplay: false,
  86. fullscreenToggle: true, // 全屏按钮
  87. },
  88. },
  89. ],
  90. };
  91. },
  92. },
  93. };
  94. </script>
  95. <style lang="scss" scoped>
  96. .liveD {
  97. position: relative;
  98. width: 100%;
  99. height: 100%;
  100. padding: 44px 0 0 0;
  101. box-sizing: border-box;
  102. overflow-y: scroll;
  103. background: transparent;
  104. // #videoPlayer {
  105. // width: 100% !important;
  106. // .video-js {
  107. // margin: 0 !important;
  108. // padding: 0 !important;
  109. // .vjs-big-play-button {
  110. // top: 20px!important;
  111. // left: 150px!important;
  112. // }
  113. // }
  114. // }
  115. // .liveD-title {
  116. // position: fixed;
  117. // padding: 0;
  118. // width: 100%;
  119. // margin: 0;
  120. // top: 0;
  121. // left: 0;
  122. // z-index: 3;
  123. // border: 0;
  124. // height: 44px;
  125. // }
  126. }
  127. // .liveD {
  128. // text-align: center;
  129. // }
  130. </style>