Fix:多视频只能播放一个

This commit is contained in:
modendeveloper
2024-12-18 23:34:57 +08:00
parent 27c95042d4
commit 78e0937fca
2 changed files with 38 additions and 4 deletions
+32 -3
View File
@@ -29,7 +29,15 @@
/>
</view>
<view class="info-item-body" v-if="item.contentType === 2">
<video play-btn-position="center" :show-fullscreen-btn="false" class="kd-cover v12-mt-0" :src="item.images[0]" controls autoplay :poster="item.images[0] + '?vframe/jpg/offset/1'"></video>
<video
@play="infoItemViewClick(item, index)"
play-btn-position="center"
:show-fullscreen-btn="false"
class="kd-cover v12-mt-0"
:src="item.images[0]"
controls
:id="'video-item' + index"
:poster="item.images[0] + '?vframe/jpg/offset/1'"></video>
</view>
<view class="info-item-bottom">
<view class="time">
@@ -83,7 +91,8 @@ export default {
data() {
return {
webUrl: this.$VUE_APP_RESOURCES_URL,
actives: this.infoArray
actives: this.infoArray,
videoPlayers: []
}
},
watch: {
@@ -92,7 +101,27 @@ export default {
}
},
methods: {
infoItemViewClick(item) {
infoItemViewClick(item, index) {
if(item.contentType === 2) {
// const coverCtx = uni.createVideoContext('coverVideo', this)
// coverCtx.pause()
const playerId = 'video-item' + index
if(this.videoPlayers.includes(playerId)) {
this.videoPlayers.forEach(player => {
if(player === playerId) return
const playerCtx = uni.createVideoContext(player, this)
playerCtx.pause()
})
} {
this.videoPlayers.push(playerId)
this.videoPlayers.forEach(player => {
if(player === playerId) return
const playerCtx = uni.createVideoContext(player, this)
playerCtx.pause()
})
}
this.$emit('video')
}
uni.$u.debounce(() => {
watchTownActive({ id: item.id }).finally(() => {
this.actives.forEach(info => {