vodShort.vue 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <template name="vodShort">
  2. <view class="swiper">
  3. <video
  4. :src="item.video"
  5. preload
  6. show-play-btn="true"
  7. controls="false"
  8. loop="true"
  9. :id="`video_${item.id}`"
  10. objectFit="fill"
  11. :enable-progress-gesture="false"
  12. @click="play"
  13. ref="video_url"
  14. play-btn-position="center"
  15. class="video"
  16. :poster="item.pic"
  17. @timeupdate="timeupdate">
  18. </video>
  19. <cover-image
  20. class="play"
  21. @tap="play"
  22. src="../../../static/video/play.png"></cover-image>
  23. </view>
  24. </template>
  25. <script>
  26. var play = false;
  27. export default {
  28. name: "vodShort",
  29. props: {
  30. item : {
  31. type : Object,
  32. value : null
  33. },
  34. },
  35. methods:{
  36. play() {
  37. let video_id = this.video_list[this.current_index].video_id;
  38. if (play) {
  39. console.log('播放视频',`video_${video_id}`);
  40. this.videoCtx = uni.createVideoContext(`video_${video_id}`, this);
  41. this.videoCtx.play();
  42. this.show_play = false;
  43. play = false;
  44. } else {
  45. console.log('暂停视频',`video_${video_id}`);
  46. this.videoCtx = uni.createVideoContext(`video_${video_id}`, this);
  47. this.videoCtx.pause();
  48. this.show_play = true;
  49. play = true;
  50. }
  51. },
  52. pause() {
  53. let video_id = this.video_list[this.current_index].video_id;
  54. this.videoCtx = uni.createVideoContext(`video_${video_id}`, this);
  55. this.videoCtx.pause();
  56. this.show_play = true;
  57. play = true;
  58. },
  59. },
  60. }
  61. </script>
  62. <style>
  63. .swiper{
  64. width: 100vw;
  65. height: 100vh;
  66. position: fixed;
  67. top: 0;
  68. left: 0;
  69. }
  70. .video {
  71. width: 100%;
  72. height: 100%;
  73. position: relative;
  74. }
  75. .play{
  76. position: absolute;
  77. width: 20vw;
  78. height: 20vw;
  79. left: 40vw;
  80. top: 40vh;
  81. opacity: 0.5;
  82. }
  83. </style>