Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

我想实现当页面有多个视频时,点击播放视频将其他以播放视频暂停 #141

Open
Libpzzz opened this issue Jan 8, 2024 · 1 comment

Comments

@Libpzzz
Copy link

Libpzzz commented Jan 8, 2024

组件绑定的事件
@play="onPlay"

const onPlay = (ev) => {
nextTick(()=>{
let videoPlays = document.getElementsByClassName('videoPlay')
if(videoPlays && videoPlays.length > 1){
for (const video of videoPlays) {
console.log(videoPlayRef.value,video.paused);
if (ev.srcElement && ev.srcElement !== video && !video.paused) {
video.pause()
}
}
}
})
}
但是这样好像只有里面的video暂停了,但是底部的组件好像没有判断出已经展厅了,左下角还是播放的图标,且点击我使用video.pause()暂停的视频之后还是显示暂停

@Libpzzz
Copy link
Author

Libpzzz commented Jan 8, 2024

解决了,我发现这个标签的父级的同级的input标签绑定了点击事件来控制视频的播放跟暂停,然后我改了监听播放的事件:
const onPlay = (ev) => {
nextTick(()=>{
let videoPlays = document.getElementsByClassName('videoPlay')
if(videoPlays && videoPlays.length > 1){
for (const video of videoPlays) {
if (ev.srcElement && ev.srcElement !== video && !video.paused) {
// 获取父级标签
const parentElement = video.parentElement.parentElement;
const input = parentElement.querySelector('input.d-player-input');
input.click()
}
}
}
})
}
但是不知道会不会有什么其他问题

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant