app-goods-video.vue 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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. console.log(`video_${this.video_id}`);
  56. this.videoCtx = uni.createVideoContext(`video_${this.video_id}`, this);
  57. if (this.play) {
  58. this.videoCtx.play();
  59. } else {
  60. this.videoCtx.pause();
  61. }
  62. },
  63. waiting(data) {
  64. this.loading = false;
  65. console.log(data);
  66. },
  67. pause(data) {
  68. console.log('暂停');
  69. },
  70. setPlay() {
  71. this.loading = true;
  72. }
  73. },
  74. watch: {
  75. play: {
  76. handler() {
  77. console.log(1);
  78. this.videoPlay();
  79. },
  80. },
  81. }
  82. };
  83. </script>
  84. <style lang="scss" scoped>
  85. .video {
  86. width: 100%;
  87. height: 100%;
  88. position: relative;
  89. }
  90. .video-con {
  91. position: relative;
  92. }
  93. .pause {
  94. width: #{128upx};
  95. height: #{128upx};
  96. position: absolute;
  97. top: 50%;
  98. left: 50%;
  99. transform: translate(-50%, -50%);
  100. }
  101. .loading {
  102. width: #{80upx};
  103. height: #{80upx};
  104. position: absolute;
  105. top: 50%;
  106. left: 50%;
  107. transform: translate(-50%, -50%);
  108. }
  109. </style>