Handle durationchange events in MessageAudio

This commit is contained in:
Fedor Indutny 2021-05-24 09:30:50 -07:00 committed by GitHub
parent d605daa04f
commit 05306c2d3d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -268,14 +268,24 @@ export const MessageAudio: React.FC<Props> = (props: Props) => {
audio.currentTime = currentTime;
};
const onDurationChange = () => {
window.log.info('MessageAudio: `durationchange` event', id);
if (!Number.isNaN(audio.duration)) {
setDuration(Math.max(audio.duration, 1e-23));
}
};
audio.addEventListener('timeupdate', onTimeUpdate);
audio.addEventListener('ended', onEnded);
audio.addEventListener('loadedmetadata', onLoadedMetadata);
audio.addEventListener('durationchange', onDurationChange);
return () => {
audio.removeEventListener('timeupdate', onTimeUpdate);
audio.removeEventListener('ended', onEnded);
audio.removeEventListener('loadedmetadata', onLoadedMetadata);
audio.removeEventListener('durationchange', onDurationChange);
};
}, [id, audio, isActive, currentTime]);