1
0

app-goods-video.vue 2.3 KB

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