app-goods-video.vue 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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="!noimg&&!play" class="pause" src="/static/image/video-play.png"></image>
  21. <image v-if="!noimg&&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. noimg: {
  36. type: Boolean,
  37. default: false
  38. },
  39. play: {
  40. type: Boolean,
  41. default: false
  42. },
  43. height: {
  44. type: String,
  45. default: ''
  46. },
  47. width: {
  48. type: String,
  49. default: ''
  50. }
  51. },
  52. data() {
  53. return {
  54. loading: true,
  55. }
  56. },
  57. methods: {
  58. videoPlay() {
  59. // #ifndef MP-ALIPAY
  60. this.videoCtx = uni.createVideoContext(`video_${this.video_id}`, this);
  61. // #endif
  62. // #ifdef MP-ALIPAY
  63. this.videoCtx = my.createVideoContext(`video_${this.video_id}`, this);
  64. // #endif
  65. if (this.play) {
  66. this.videoCtx.play();
  67. } else {
  68. this.videoCtx.pause();
  69. }
  70. },
  71. waiting() {
  72. this.loading = false;
  73. },
  74. pause() {
  75. },
  76. setPlay() {
  77. this.loading = true;
  78. }
  79. },
  80. watch: {
  81. play: {
  82. handler() {
  83. this.videoPlay();
  84. },
  85. },
  86. },
  87. beforeDestroy() {
  88. // this.videoCtx.stop();
  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>