Fix:3002 【商城小程序】优化评论列表中多个视频不能同时播放,播放下一个视频自动暂停前一个正在播放的视频

This commit is contained in:
modendeveloper
2025-01-08 21:17:56 +08:00
parent 02627db525
commit dc8069bca1
+17 -1
View File
@@ -26,7 +26,9 @@
:poster="item.video + '?vframe/jpg/offset/1'" :poster="item.video + '?vframe/jpg/offset/1'"
controls controls
play-btn-position="center" play-btn-position="center"
:id="'video' + evaluateWtapperIndex"
class="image" class="image"
@play="pauseOtherVideo('video' + evaluateWtapperIndex)"
/> />
</view> </view>
<view <view
@@ -56,7 +58,9 @@ export default {
} }
}, },
data: function() { data: function() {
return {}; return {
videoPlayers: []
};
}, },
mounted: function() {}, mounted: function() {},
methods: { methods: {
@@ -66,6 +70,18 @@ export default {
current:imgs[index], current:imgs[index],
urls:imgs urls:imgs
}) })
},
// 播放视频时暂停其他视频
pauseOtherVideo(video) {
if(this.videoPlayers.includes(video)) {
this.videoPlayers.forEach((item) => {
if(item !== video) {
uni.createVideoContext(item, this).pause();
}
})
} else {
this.videoPlayers.push(video);
}
} }
} }
}; };