[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:
parent
988c6931ec
commit
438b69b371
|
@ -20,6 +20,8 @@ import { TGetCustomEmoji } from '../../definitions/IEmoji';
|
||||||
import { IAttachment } from '../../definitions';
|
import { IAttachment } from '../../definitions';
|
||||||
import { TSupportedThemes } from '../../theme';
|
import { TSupportedThemes } from '../../theme';
|
||||||
import { downloadAudioFile } from '../../lib/methods/audioFile';
|
import { downloadAudioFile } from '../../lib/methods/audioFile';
|
||||||
|
import EventEmitter from '../../lib/methods/helpers/events';
|
||||||
|
import { PAUSE_AUDIO } from './constants';
|
||||||
|
|
||||||
interface IButton {
|
interface IButton {
|
||||||
loading: boolean;
|
loading: boolean;
|
||||||
|
@ -128,6 +130,11 @@ class MessageAudio extends React.Component<IMessageAudioProps, IMessageAudioStat
|
||||||
this.sound.setOnPlaybackStatusUpdate(this.onPlaybackStatusUpdate);
|
this.sound.setOnPlaybackStatusUpdate(this.onPlaybackStatusUpdate);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pauseSound = () => {
|
||||||
|
EventEmitter.removeListener(PAUSE_AUDIO, this.pauseSound);
|
||||||
|
this.togglePlayPause();
|
||||||
|
};
|
||||||
|
|
||||||
async componentDidMount() {
|
async componentDidMount() {
|
||||||
const { file, messageId } = this.props;
|
const { file, messageId } = this.props;
|
||||||
const { baseUrl, user } = this.context;
|
const { baseUrl, user } = this.context;
|
||||||
|
@ -183,6 +190,7 @@ class MessageAudio extends React.Component<IMessageAudioProps, IMessageAudioStat
|
||||||
}
|
}
|
||||||
|
|
||||||
async componentWillUnmount() {
|
async componentWillUnmount() {
|
||||||
|
EventEmitter.removeListener(PAUSE_AUDIO, this.pauseSound);
|
||||||
try {
|
try {
|
||||||
await this.sound.stopAsync();
|
await this.sound.stopAsync();
|
||||||
} catch {
|
} catch {
|
||||||
|
@ -221,6 +229,7 @@ class MessageAudio extends React.Component<IMessageAudioProps, IMessageAudioStat
|
||||||
try {
|
try {
|
||||||
await this.sound.stopAsync();
|
await this.sound.stopAsync();
|
||||||
this.setState({ paused: true, currentTime: 0 });
|
this.setState({ paused: true, currentTime: 0 });
|
||||||
|
EventEmitter.removeListener(PAUSE_AUDIO, this.pauseSound);
|
||||||
} catch {
|
} catch {
|
||||||
// do nothing
|
// do nothing
|
||||||
}
|
}
|
||||||
|
@ -243,7 +252,10 @@ class MessageAudio extends React.Component<IMessageAudioProps, IMessageAudioStat
|
||||||
try {
|
try {
|
||||||
if (paused) {
|
if (paused) {
|
||||||
await this.sound.pauseAsync();
|
await this.sound.pauseAsync();
|
||||||
|
EventEmitter.removeListener(PAUSE_AUDIO, this.pauseSound);
|
||||||
} else {
|
} else {
|
||||||
|
EventEmitter.emit(PAUSE_AUDIO);
|
||||||
|
EventEmitter.addEventListener(PAUSE_AUDIO, this.pauseSound);
|
||||||
await Audio.setAudioModeAsync(mode);
|
await Audio.setAudioModeAsync(mode);
|
||||||
await this.sound.playAsync();
|
await this.sound.playAsync();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,2 +1,3 @@
|
||||||
export const DISCUSSION = 'discussion';
|
export const DISCUSSION = 'discussion';
|
||||||
export const THREAD = 'thread';
|
export const THREAD = 'thread';
|
||||||
|
export const PAUSE_AUDIO = 'pause_audio';
|
||||||
|
|
Loading…
Reference in New Issue