Feature - Prevents multiple audio/video attachments from being played at the same time (#24717)
This commit is contained in:
parent
389a6cc4c0
commit
d3cd37d73e
4 changed files with 140 additions and 11 deletions
|
@ -22,6 +22,7 @@ import { Icon } from 'mastodon/components/icon';
|
|||
import { playerSettings } from 'mastodon/settings';
|
||||
|
||||
import { displayMedia, useBlurhash } from '../../initial_state';
|
||||
import { currentMedia, setCurrentMedia } from '../../reducers/media_attachments';
|
||||
import { isFullscreen, requestFullscreen, exitFullscreen } from '../ui/util/fullscreen';
|
||||
|
||||
const messages = defineMessages({
|
||||
|
@ -181,6 +182,7 @@ class Video extends PureComponent {
|
|||
};
|
||||
|
||||
handlePause = () => {
|
||||
this.video.pause();
|
||||
this.setState({ paused: true });
|
||||
};
|
||||
|
||||
|
@ -344,11 +346,32 @@ class Video extends PureComponent {
|
|||
};
|
||||
|
||||
togglePlay = () => {
|
||||
if (this.state.paused) {
|
||||
this.setState({ paused: false }, () => this.video.play());
|
||||
} else {
|
||||
this.setState({ paused: true }, () => this.video.pause());
|
||||
const videos = document.querySelectorAll('video');
|
||||
|
||||
videos.forEach((video) => {
|
||||
const button = video.nextElementSibling;
|
||||
button.addEventListener('click', () => {
|
||||
if (video.paused) {
|
||||
videos.forEach((e) => {
|
||||
if (e !== video) {
|
||||
e.pause();
|
||||
}
|
||||
});
|
||||
video.play();
|
||||
this.setState({ paused: false });
|
||||
} else {
|
||||
video.pause();
|
||||
this.setState({ paused: true });
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
if (currentMedia !== null) {
|
||||
currentMedia.pause();
|
||||
}
|
||||
|
||||
this.video.play();
|
||||
setCurrentMedia(this.video);
|
||||
};
|
||||
|
||||
toggleFullscreen = () => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue