app-goods-video.vue 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. <template>
  2. <view
  3. class="video-con"
  4. :style="{ height: height, width: width }"
  5. >
  6. <video
  7. :src="video_url"
  8. preload
  9. :controls="controls"
  10. :style="{ height: height, width: width }"
  11. :loop="true"
  12. :id="`video_${video_id}`"
  13. :enable-progress-gesture="false"
  14. :show-center-play-btn="false"
  15. :show-play-btn="false"
  16. :show-fullscreen-btn="false"
  17. class="video"
  18. @play="setPlay"
  19. @waiting="waiting"
  20. @pause="pause"
  21. >
  22. </video>
  23. <image v-if="!play" class="pause" src="/static/image/video-play.png"></image>
  24. <image v-if="play && !loading" class="loading" src="/static/image/icon/loading.gif"></image>
  25. </view>
  26. </template>
  27. <script>
  28. export default {
  29. props: {
  30. video_id: {
  31. type: Number,
  32. default: 0
  33. },
  34. video_url: {
  35. type: String,
  36. default: ''
  37. },
  38. play: {
  39. type: Boolean,
  40. default: false
  41. },
  42. height: {
  43. type: String,
  44. default: ''
  45. },
  46. width: {
  47. type: String,
  48. default: ''
  49. }
  50. },
  51. data() {
  52. return {
  53. loading: true,
  54. videoCtx: null,
  55. controls: false
  56. }
  57. },
  58. methods: {
  59. videoPlay() {
  60. // #ifndef MP-ALIPAY
  61. this.videoCtx = uni.createVideoContext(`video_${this.video_id}`, this);
  62. // #endif
  63. // #ifdef MP-ALIPAY
  64. this.videoCtx = my.createVideoContext(`video_${this.video_id}`, this);
  65. // #endif
  66. if (this.play) {
  67. this.videoCtx.play();
  68. } else {
  69. this.videoCtx.pause();
  70. }
  71. },
  72. waiting() {
  73. this.loading = false;
  74. },
  75. pause() {
  76. },
  77. setPlay() {
  78. this.loading = true;
  79. }
  80. },
  81. watch: {
  82. play: {
  83. handler() {
  84. this.videoPlay();
  85. },
  86. },
  87. },
  88. beforeDestroy() {
  89. this.videoCtx = null;
  90. }
  91. };
  92. </script>
  93. <style lang="scss" scoped>
  94. .video {
  95. width: 100%;
  96. height: 100%;
  97. position: relative;
  98. }
  99. .video-con {
  100. position: relative;
  101. }
  102. .pause {
  103. width: #{128upx};
  104. height: #{128upx};
  105. position: absolute;
  106. top: 50%;
  107. left: 50%;
  108. transform: translate(-50%, -50%);
  109. }
  110. .loading {
  111. width: #{80upx};
  112. height: #{80upx};
  113. position: absolute;
  114. top: 50%;
  115. left: 50%;
  116. transform: translate(-50%, -50%);
  117. }
  118. </style>