Feature - Prevents multiple audio/video attachments from being played at the same time (#24717)

This commit is contained in:
João Pedro Marques 2023-11-07 20:37:58 -03:00 committed by GitHub
parent 389a6cc4c0
commit d3cd37d73e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 140 additions and 11 deletions

View file

@ -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 = () => {