Skip to content

Commit

Permalink
Use HTMLMediaElement srcObject for MediaStreams if available (#13)
Browse files Browse the repository at this point in the history
Use HTMLMediaElement.srcObject in favour of deprecated URL.createObjectURL only on supported browsers by checking if the HTMLMediaElement interface is available
  • Loading branch information
sinedoOo authored and dandv committed Jan 10, 2018
1 parent f522819 commit e533e5f
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/imagecapture.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,11 @@ if (typeof ImageCapture === 'undefined') {
this.videoElementPlaying = new Promise(resolve => {
this.videoElement.addEventListener('playing', resolve);
});
this.videoElement.src = URL.createObjectURL(this._previewStream);
if (HTMLMediaElement) {
this.videoElement.srcObject = this._previewStream; // Safari 11 doesn't allow use of createObjectURL for MediaStream
} else {
this.videoElement.src = URL.createObjectURL(this._previewStream);
}
this.videoElement.muted = true;
this.videoElement.setAttribute('playsinline', ''); // Required by Safari on iOS 11. See https://webkit.org/blog/6784
this.videoElement.play();
Expand Down

0 comments on commit e533e5f

Please sign in to comment.