.vue 文件

<video   :data-id="item.id" :key="item.id" :id="'video'+item.id" :src="item.videoUrl"  object-fit:fill
                enable-danmu danmu-btn controls 
                webkit-playsinline playsinline x5-video-player-type="h5" x5-video-orientation="portraint"
                @play="playing" @pause="pause"
                 @error="videoErrorCallback" :danmu-list="danmuList"  ></video>
.js 文件

        playing(e) {
            
            let currentId = 'video' + e.currentTarget.dataset.id;// 获取当前视频id
            console.log("currentId", currentId);
            this.videoContent = uni.createVideoContext(currentId);
            console.log("this.videoContent", this.videoContent)
        
            let trailer = this.dynListData;
 
            trailer.forEach(function(item, index) {    // 获取json对象并遍历, 停止非当前视频
                if (item.videoUrl != null && item.videoUrl != "") {
                    let temp = 'video' + item.id;
                    if (temp != currentId) {
                        console.log(temp);
                        uni.createVideoContext(temp).pause(); //暂停视频播放事件
                    }
                }
 
            })
 
        }
 

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐