为什么在swiper中绑定touchVideoStart事件获取videoContext暂停无效?
<swiper indicator-dots="{{indicatorDots}}" interval="{{interval}}" duration="{{duration}}" vertical="true" style="height:{{windowHeight}}px;width:{{windowWidth}}px" bindchange="changeVideo" bindtap=""> <block wx:for="{{videoList}}" wx:key="videoList"> <swiper-item> <video id="myVideo{{index}}" class="vid" src="{{item}}" controls="false" bindtouchstart="touchVideoStart" bindtouchend="touchVideoEnd" autoplay="{{index == current}}"></video> </swiper-item> </block> </swiper> |
/** * 开始滑动 */ touchVideoStart: function(e) { console.log('touchVideoStart', e); let video = e.currentTarget.id; console.log('video', video); debugger this.videoContext = wx.createVideoContext(video);//videoContext报错 undefind console.log('videoContext', videoContext); this.videoContext.pause(); }, |
需求是做成像抖音或者快手一样是视频滑动的时候控制上一个视频停止和下一个视频播放
目前运行此代码报错信息为:
videoContext is not defined; [Component] Event Handler Error @ index/index#bound touchVideoStart
ReferenceError: videoContext is not defined
导致报错的原因是什么?还有就是有更好的解决需求方案么?最好是不花钱,谢谢。
