From af659d662c715fc5313d777e4feef0ac2f77f1c8 Mon Sep 17 00:00:00 2001 From: Francisco Baio Dias Date: Tue, 4 Jun 2019 18:06:41 +0200 Subject: [PATCH] feat: try to autoplay replay video with sound --- src/video-recorder.js | 38 +++++++++++++++++++++++++------------- 1 file changed, 25 insertions(+), 13 deletions(-) diff --git a/src/video-recorder.js b/src/video-recorder.js index 49dc024..90881ad 100644 --- a/src/video-recorder.js +++ b/src/video-recorder.js @@ -171,19 +171,7 @@ export default class VideoRecorder extends Component { this.state.isReplayingVideo && !prevState.isReplayingVideo ) { - this.replayVideo.addEventListener('loadedmetadata', () => { - const playPromise = this.replayVideo.play() - - if (playPromise) { - playPromise.catch(err => { - if (err.name === 'NotAllowedError') { - console.warn(err) - return - } - throw err - }) - } - }) + this.tryToUnmuteReplayVideo() } } @@ -299,6 +287,30 @@ export default class VideoRecorder extends Component { return true } + tryToUnmuteReplayVideo = () => { + const video = this.replayVideo + video.muted = false + + let playPromise = video.play() + if (!playPromise) { + video.muted = true + return + } + + playPromise + .then(() => { + this.setState({ isReplayVideoMuted: false }) + }) + .catch(err => { + console.warn('Could not autoplay replay video', err) + video.muted = true + return video.play() + }) + .catch(err => { + console.warn('Could play muted replay video after failed autoplay', err) + }) + } + handleDataAvailable (event) { if (this.isDataHealthOK(event)) { this.recordedBlobs.push(event.data)