Skip to content

Commit

Permalink
feat: try to autoplay replay video with sound
Browse files Browse the repository at this point in the history
  • Loading branch information
fbaiodias committed Jun 4, 2019
1 parent abb088f commit af659d6
Showing 1 changed file with 25 additions and 13 deletions.
38 changes: 25 additions & 13 deletions src/video-recorder.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}

Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit af659d6

Please sign in to comment.