dont re-prepare voice messages (#7897)

* dont reprepare voice messages

Signed-off-by: Kerry Archibald <kerrya@element.io>

* remove debug

Signed-off-by: Kerry Archibald <kerrya@element.io>

* test Playback

Signed-off-by: Kerry Archibald <kerrya@element.io>

* test RecordingPlayback

Signed-off-by: Kerry Archibald <kerrya@element.io>

* forgotten copyright

Signed-off-by: Kerry Archibald <kerrya@element.io>

* add comments

Signed-off-by: Kerry Archibald <kerrya@element.io>
This commit is contained in:
Kerry 2022-03-01 09:43:32 +01:00 committed by GitHub
parent 16e67e7716
commit 4bf42babc7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 338 additions and 1 deletions

View file

@ -133,6 +133,13 @@ export class Playback extends EventEmitter implements IDestroyable {
}
public async prepare() {
// don't attempt to decode the media again
// AudioContext.decodeAudioData detaches the array buffer `this.buf`
// meaning it cannot be re-read
if (this.state !== PlaybackState.Decoding) {
return;
}
// The point where we use an audio element is fairly arbitrary, though we don't want
// it to be too low. As of writing, voice messages want to show a waveform but audio
// messages do not. Using an audio element means we can't show a waveform preview, so

View file

@ -40,8 +40,9 @@ export default abstract class AudioPlayerBase extends React.PureComponent<IProps
constructor(props: IProps) {
super(props);
// Playback instances can be reused in the composer
this.state = {
playbackPhase: PlaybackState.Decoding, // default assumption
playbackPhase: this.props.playback.currentState,
};
// We don't need to de-register: the class handles this for us internally

View file

@ -59,7 +59,9 @@ export default class PlayPauseButton extends React.PureComponent<IProps> {
'mx_PlayPauseButton_pause': isPlaying,
'mx_PlayPauseButton_disabled': isDisabled,
});
return <AccessibleTooltipButton
data-test-id='play-pause-button'
className={classes}
title={isPlaying ? _t("Pause") : _t("Play")}
onClick={this.onClick}

View file

@ -36,6 +36,7 @@ export default class RecordingPlayback extends AudioPlayerBase {
protected renderComponent(): ReactNode {
const shapeClass = !this.isWaveformable ? 'mx_VoiceMessagePrimaryContainer_noWaveform' : '';
return (
<div className={'mx_MediaBody mx_VoiceMessagePrimaryContainer ' + shapeClass}>
<PlayPauseButton playback={this.props.playback} playbackPhase={this.state.playbackPhase} />