index.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. <template>
  2. <view class="container global-video-box" v-if="showVideoPop">
  3. <view class="video-content">
  4. <video
  5. :id="videoPopList.Id"
  6. :src="videoPopList.ResourceUrl"
  7. :poster="videoPopList.BackgroundImg"
  8. enable-play-gesture
  9. :custom-cache="false"
  10. object-fit="contain"
  11. show-mute-btn
  12. @ended="handleVideoEnd"
  13. @timeupdate="handleVideoTimeUpdate"
  14. @fullscreenchange="handleFullscreenchange"
  15. autoplay
  16. >
  17. <view class="video-inner-right-box" v-if="isShowControls">
  18. <!-- 倍速控制按钮 -->
  19. <view class="video-speed-btn" @click.stop="showSpeedOpt = true">倍速</view>
  20. </view>
  21. <!-- 倍速选项模块 -->
  22. <view class="speed-opt-box" v-if="showSpeedOpt">
  23. <view class="item" :style="{ color: item == curSpeed ? '#F3A52F' : '' }" v-for="item in speedOpts" :key="item" @click.stop="handleVideoSpeedChange(item)">{{ item }}X</view>
  24. </view>
  25. </video>
  26. <view class="title text_twoLine">
  27. {{ videoPopList.Title }}
  28. </view>
  29. </view>
  30. <view class="close-icon" v-if="showCloseBtn">
  31. <image @click="handleShow" src="https://hzchart.oss-cn-shanghai.aliyuncs.com/cygx/close-icon.png"> </image>
  32. </view>
  33. </view>
  34. </template>
  35. <script>
  36. import { Home } from "@/config/api";
  37. export default {
  38. name: "",
  39. filters: {},
  40. components: {},
  41. props: {
  42. showVideoPop: {
  43. default: false,
  44. type: Boolean,
  45. },
  46. videoPopList: {
  47. default: {},
  48. type: Object,
  49. },
  50. },
  51. computed: {
  52. curVideoId() {
  53. return this.$store.state.videoPlay.playVideoId;
  54. },
  55. activityVideoId() {
  56. return this.$store.state.videoPlay.playVideoActId;
  57. },
  58. },
  59. data() {
  60. return {
  61. videoContext: null,
  62. curVideoTime: 0,
  63. showSpeedOpt: false,
  64. speedOpts: ["0.5", "0.8", "1.0", "1.25", "1.5", "2.0"],
  65. curSpeed: "1.0",
  66. isShowControls: false, //是否显示视频的控制栏
  67. showCloseBtn: true,
  68. };
  69. },
  70. watch: {
  71. showVideoPop: {
  72. handler(newVal) {
  73. if (newVal) {
  74. setTimeout(() => {
  75. this.handelVideoPlayChild();
  76. }, 300);
  77. }
  78. },
  79. },
  80. },
  81. created() {},
  82. mounted() {},
  83. methods: {
  84. //视频的播放事件
  85. handelVideoPlayChild() {
  86. this.videoContext = wx.createVideoContext(this.videoPopList.Id.toString(), this);
  87. Home.microAideoHistoryAdd({ SourceId: this.videoPopList.ActivityId || this.videoPopList.Id, SourceType: this.videoPopList.ActivityId ? 2 : 3, PageRouter: this.$store.state.pageRouterReport });
  88. this.curVideoTime = 0;
  89. if (this.curVideoId == this.videoPopList.Id || this.activityVideoId == this.videoPopList.ActivityId) {
  90. this.curVideoTime = this.$store.state.videoPlay.palyCurrentTime;
  91. }
  92. this.videoContext.seek(this.curVideoTime);
  93. this.videoContext.play();
  94. },
  95. //视频播放结束
  96. handleVideoEnd() {
  97. // 此处因为如果不调用退出全屏方法 安卓和ios页面均会表现异常,安卓横屏不恢复竖屏,ios底部tabbar渲染异常
  98. this.curVideoTime = 0;
  99. this.$store.commit("videoPlay/palyTimeUpdate", 0);
  100. this.videoContext.exitFullScreen();
  101. },
  102. handleVideoTimeUpdate(e) {
  103. let time = parseInt(e.detail.currentTime);
  104. this.$store.commit("videoPlay/palyTimeUpdate", time);
  105. },
  106. handleShow() {
  107. this.showSpeedOpt = false;
  108. this.curSpeed = "1.0";
  109. // this.$parent.showVideoPop = false;
  110. this.$emit("update:showVideoPop", false);
  111. },
  112. // 倍速切换
  113. handleVideoSpeedChange(item) {
  114. const num = Number(item);
  115. this.videoContext.playbackRate(num);
  116. this.curSpeed = item;
  117. this.showSpeedOpt = false;
  118. },
  119. handleFullscreenchange(e) {
  120. this.showCloseBtn = !e.detail.fullScreen;
  121. this.isShowControls = e.detail.fullScreen;
  122. },
  123. },
  124. };
  125. </script>
  126. <style scoped lang="scss">
  127. .global-video-box {
  128. display: flex;
  129. height: 100%;
  130. position: fixed;
  131. width: 100%;
  132. top: 0;
  133. left: 0;
  134. z-index: 111;
  135. background-color: rgba(0, 0, 0, 0.7);
  136. .video-content {
  137. position: absolute;
  138. top: 500rpx;
  139. left: 50%;
  140. transform: translateX(-50%);
  141. width: 95%;
  142. height: 456rpx;
  143. background-color: #fff;
  144. z-index: 112;
  145. font-size: 28rpx;
  146. color: #333333;
  147. video {
  148. width: 100%;
  149. height: 340rpx;
  150. }
  151. .title {
  152. padding: 15rpx 0 0 15rpx;
  153. }
  154. }
  155. .close-icon {
  156. position: absolute;
  157. width: 95%;
  158. height: 48rpx;
  159. top: 430rpx;
  160. left: 50%;
  161. transform: translateX(-50%);
  162. z-index: 112;
  163. display: flex;
  164. justify-content: flex-end;
  165. z-index: inherit;
  166. image {
  167. height: 48rpx;
  168. width: 48rpx;
  169. }
  170. }
  171. .video-inner-right-box {
  172. position: absolute;
  173. bottom: 30%;
  174. right: 5%;
  175. display: flex;
  176. flex-direction: column;
  177. align-items: center;
  178. }
  179. .video-speed-btn {
  180. width: 80rpx;
  181. height: 44rpx;
  182. display: flex;
  183. align-items: center;
  184. justify-content: center;
  185. background: rgba(0, 0, 0, 0.4);
  186. border-radius: 22rpx;
  187. color: #fff;
  188. font-size: 12px;
  189. }
  190. .speed-opt-box {
  191. position: absolute;
  192. right: 0;
  193. top: 0;
  194. bottom: 0;
  195. width: 20%;
  196. background: rgba(0, 0, 0, 0.8);
  197. display: flex;
  198. flex-direction: column;
  199. justify-content: space-around;
  200. padding-top: 55rpx;
  201. .item {
  202. color: #fff;
  203. font-size: 26rpx;
  204. flex: 1;
  205. width: 100%;
  206. text-align: center;
  207. }
  208. }
  209. }
  210. </style>