猎豆优选小程序

videoPlayer.vue 1.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <template>
  2. <view class="video-wrap">
  3. <image class="filterBgImg" :src="video_info.imageUrl"></image>
  4. <video class="myVideo" :style="{height: `${100 * video_info.high / video_info.width}vw`}" @click="click" @play="changePlay" :id="'myVideo'+ goods_id" :poster="video_info.imageUrl" :src="video_info.playUrl" :loop="true"></video>
  5. </view>
  6. </template>
  7. <script>
  8. export default{
  9. props: ['video_info', 'goods_id', 'imgSwiperGoodsId'],
  10. data(){
  11. return{
  12. play: false
  13. }
  14. },
  15. watch:{
  16. imgSwiperGoodsId(){ // imgSwiperGoodsId 与 goods-id一致 则播放视频,否则关闭视频
  17. if ( this.imgSwiperGoodsId == this.goods_id) {
  18. this.playVideo()
  19. } else {
  20. this.pauseVideo()
  21. }
  22. }
  23. },
  24. onReady() {
  25. this.videoContext = uni.createVideoContext("myVideo" + this.goods_id, this)
  26. },
  27. mounted() {
  28. this.videoContext = uni.createVideoContext("myVideo" + this.goods_id, this)
  29. },
  30. methods:{
  31. click() {
  32. if (!this.play) {
  33. this.playthis()
  34. } else {
  35. this.pauseVideo()
  36. }
  37. },
  38. playVideo() {
  39. if (this.play === false) {
  40. this.videoContext.seek(0)
  41. this.videoContext.play()
  42. this.play = true
  43. }
  44. },
  45. pauseVideo() {
  46. if (this.play === true) {
  47. this.videoContext.pause()
  48. this.play = false
  49. }
  50. },
  51. playthis() {
  52. if (this.play === false) {
  53. this.videoContext.play()
  54. this.play = true
  55. }
  56. },
  57. changePlay() {
  58. this.play = true
  59. }
  60. }
  61. }
  62. </script>
  63. <style lang="scss" scoped>
  64. .video-wrap{
  65. width:100%;
  66. height:100%;
  67. position: relative;
  68. z-index:-1;
  69. .myVideo{
  70. width:100vw;
  71. height: 100vw;
  72. position: absolute;
  73. top:0;
  74. bottom:0;
  75. margin:auto;
  76. }
  77. }
  78. .filterBgImg{
  79. width: 100%;
  80. height: 100%;
  81. position: absolute;
  82. top: 0;
  83. left: 0;
  84. filter: blur(45px)
  85. }
  86. </style>