0
0
Fork 0

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

@ -20,6 +20,7 @@ import { formatTime, getPointerPosition, fileNameFromURL } from 'mastodon/featur
import { Blurhash } from '../../components/blurhash';
import { displayMedia, useBlurhash } from '../../initial_state';
import { currentMedia, setCurrentMedia } from '../../reducers/media_attachments';
import Visualizer from './visualizer';
@ -165,15 +166,32 @@ class Audio extends PureComponent {
}
togglePlay = () => {
if (!this.audioContext) {
this._initAudioContext();
const audios = document.querySelectorAll('audio');
audios.forEach((audio) => {
const button = audio.previousElementSibling;
button.addEventListener('click', () => {
if(audio.paused) {
audios.forEach((e) => {
if (e !== audio) {
e.pause();
}
});
audio.play();
this.setState({ paused: false });
} else {
audio.pause();
this.setState({ paused: true });
}
});
});
if (currentMedia !== null) {
currentMedia.pause();
}
if (this.state.paused) {
this.setState({ paused: false }, () => this.audio.play());
} else {
this.setState({ paused: true }, () => this.audio.pause());
}
this.audio.play();
setCurrentMedia(this.audio);
};
handleResize = debounce(() => {
@ -195,6 +213,7 @@ class Audio extends PureComponent {
};
handlePause = () => {
this.audio.pause();
this.setState({ paused: true });
if (this.audioContext) {