Fix negative countdown for audio messages
This commit is contained in:
parent
207705bf30
commit
aa63aabbc6
1 changed files with 6 additions and 3 deletions
|
@ -201,7 +201,7 @@ export const MessageAudio: React.FC<Props> = (props: Props) => {
|
||||||
state = State.Normal;
|
state = State.Normal;
|
||||||
}
|
}
|
||||||
|
|
||||||
// This effect loads audio file and computes its RMS peak for dispalying the
|
// This effect loads audio file and computes its RMS peak for displaying the
|
||||||
// waveform.
|
// waveform.
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (state !== State.Computing) {
|
if (state !== State.Computing) {
|
||||||
|
@ -273,6 +273,9 @@ export const MessageAudio: React.FC<Props> = (props: Props) => {
|
||||||
|
|
||||||
const onTimeUpdate = () => {
|
const onTimeUpdate = () => {
|
||||||
setCurrentTime(audio.currentTime);
|
setCurrentTime(audio.currentTime);
|
||||||
|
if (audio.currentTime > duration) {
|
||||||
|
setDuration(audio.currentTime);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const onEnded = () => {
|
const onEnded = () => {
|
||||||
|
@ -313,7 +316,7 @@ export const MessageAudio: React.FC<Props> = (props: Props) => {
|
||||||
audio.removeEventListener('loadedmetadata', onLoadedMetadata);
|
audio.removeEventListener('loadedmetadata', onLoadedMetadata);
|
||||||
audio.removeEventListener('durationchange', onDurationChange);
|
audio.removeEventListener('durationchange', onDurationChange);
|
||||||
};
|
};
|
||||||
}, [id, audio, isActive, currentTime]);
|
}, [id, audio, isActive, currentTime, duration]);
|
||||||
|
|
||||||
// This effect detects `isPlaying` changes and starts/pauses playback when
|
// This effect detects `isPlaying` changes and starts/pauses playback when
|
||||||
// needed (+keeps waveform position and audio position in sync).
|
// needed (+keeps waveform position and audio position in sync).
|
||||||
|
@ -507,7 +510,7 @@ export const MessageAudio: React.FC<Props> = (props: Props) => {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const countDown = duration - currentTime;
|
const countDown = Math.max(0, duration - currentTime);
|
||||||
|
|
||||||
const metadata = (
|
const metadata = (
|
||||||
<div className={`${CSS_BASE}__metadata`}>
|
<div className={`${CSS_BASE}__metadata`}>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue