[FIX] Playing multiple voice messages at the same time (#4662)

Co-authored-by: gitstart <gitstart@users.noreply.github.com>
Co-authored-by: Debojyoti Singha <20729878+debojyoti452@users.noreply.github.com>
Co-authored-by: Diego Mello <diegolmello@gmail.com>
This commit is contained in:
GitStart 2022-11-16 14:40:45 +01:00 committed by GitHub
parent 988c6931ec
commit 438b69b371
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 0 deletions

View File

@ -20,6 +20,8 @@ import { TGetCustomEmoji } from '../../definitions/IEmoji';
import { IAttachment } from '../../definitions';
import { TSupportedThemes } from '../../theme';
import { downloadAudioFile } from '../../lib/methods/audioFile';
import EventEmitter from '../../lib/methods/helpers/events';
import { PAUSE_AUDIO } from './constants';
interface IButton {
loading: boolean;
@ -128,6 +130,11 @@ class MessageAudio extends React.Component<IMessageAudioProps, IMessageAudioStat
this.sound.setOnPlaybackStatusUpdate(this.onPlaybackStatusUpdate);
}
pauseSound = () => {
EventEmitter.removeListener(PAUSE_AUDIO, this.pauseSound);
this.togglePlayPause();
};
async componentDidMount() {
const { file, messageId } = this.props;
const { baseUrl, user } = this.context;
@ -183,6 +190,7 @@ class MessageAudio extends React.Component<IMessageAudioProps, IMessageAudioStat
}
async componentWillUnmount() {
EventEmitter.removeListener(PAUSE_AUDIO, this.pauseSound);
try {
await this.sound.stopAsync();
} catch {
@ -221,6 +229,7 @@ class MessageAudio extends React.Component<IMessageAudioProps, IMessageAudioStat
try {
await this.sound.stopAsync();
this.setState({ paused: true, currentTime: 0 });
EventEmitter.removeListener(PAUSE_AUDIO, this.pauseSound);
} catch {
// do nothing
}
@ -243,7 +252,10 @@ class MessageAudio extends React.Component<IMessageAudioProps, IMessageAudioStat
try {
if (paused) {
await this.sound.pauseAsync();
EventEmitter.removeListener(PAUSE_AUDIO, this.pauseSound);
} else {
EventEmitter.emit(PAUSE_AUDIO);
EventEmitter.addEventListener(PAUSE_AUDIO, this.pauseSound);
await Audio.setAudioModeAsync(mode);
await this.sound.playAsync();
}

View File

@ -1,2 +1,3 @@
export const DISCUSSION = 'discussion';
export const THREAD = 'thread';
export const PAUSE_AUDIO = 'pause_audio';