收藏
回答

wx.createVideoContext(id,this) 后调用pause() 无效?

制作一个类似抖音视频播放的功能,在滑动视频之后上一个视频还是在播放,无法暂停,使用的是wepy 框架

<swiper 
      class="video-swiper" 
      vertical 
      current="0"
      bindanimationfinish="animationfinish"
      >
      <swiper-item v-for="(item, index) in videoList" :key="index">
        <video 
          id="video{{index}}" 
          class="video_item" 
          enable-play-gesture 
          enable-progress-gesture
          show-center-play-btn="{{true}}"
          controls="{{true}}"
          src="{{item.url_mp4}}" 
          data-id="{{item.hid}}"
          object-fit="{{item.objectFit || 'cover'}}"
          data-index="{{index}}"
          custom-cache="{{false}}"
          bindplay="onPlay"
          bindpause="onPause"
          bindended="onEnded"
          binderror="onError"
          bindtimeupdate="onTimeUpdate"
          bindwaiting="onWaiting"
          bindprogress="onProgress"
          bindloadedmetadata="onLoadedMetaData"
        >
        </video>
      </swiper-item>
// JS
wepy.component({
  props: {
    videoList: {}
  },
  data: {
    _videoContexts:[],
    currentIndex: 0
  },
  created() {
    console.log('this.videoList',this.videoList,this.props)
    this._videoContexts=[]
  },
  watch:{
    videoList(){
      this._videoContexts=[]
      for (let i = 0; i < this.videoList.length; i++) {
        this._videoContexts.push(wx.createVideoContext('video'+i, this))
      }
    }
  },
  methods: {
    onPlay(){},
    onPause(){
      console.log('触发暂停时间-----');
    },
    onEnded(){},
    onError(){},
    onTimeUpdate(){},
    onWaiting(){},
    onProgress(){},
    onLoadedMetaData(){},
    animationfinish(e){
      let current = e.$wx.detail.current
      const _this = this;
      this.$emit('changeComment', current);
      this.currentIndex = current;
      this._videoContexts.forEach((ctx, index)=>{
        if( index == current + 1 || index == current - 1){
         //这里执行无效
          ctx.pause();
        }else{
        ctx.play()
        }
      });
    }
  }
回答关注问题邀请回答
收藏

1 个回答

  • 小蜗
    小蜗
    2020-03-30

    为什么不在swiper里写bindchange

    用bindchange来判断就能知道视频是不是切换了 切换了就暂停啊

    https://developers.weixin.qq.com/miniprogram/dev/component/swiper.html

    2020-03-30
    有用
    回复 2
    • 斌bin
      斌bin
      2020-03-30
      2020-03-30
      回复
    • 斌bin
      斌bin
      2020-03-30
      这个事件一样能判断,目前不是判断视频切换的问题,而是 视频暂停事件不生效
      2020-03-30
      回复
登录 后发表内容
问题标签