Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(browser) Closes #149 Image capture not working on Chrome browser #167

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ Thumbs.db

node_modules


/.idea
/package-lock.json



Expand Down
21 changes: 18 additions & 3 deletions src/browser/CaptureProxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,10 @@ CameraUI.prototype.startPreview = function (count, successCB, errorCB) {
navigator.getUserMedia({video: true}, function (previewStream) {
// Save video stream to be able to stop it later
that._previewStream = previewStream;
that.preview.src = URL.createObjectURL(previewStream); // eslint-disable-line no-undef

// https://github.com/apache/cordova-plugin-media-capture/issues/149
that.preview.srcObject = previewStream;

// We don't need to set visibility = true for preview element
// since this will be done automatically in onplay event handler
}, function (/* err */) {
Expand All @@ -131,10 +134,22 @@ CameraUI.prototype.startPreview = function (count, successCB, errorCB) {
CameraUI.prototype.destroyPreview = function () {
this.preview.pause();
this.preview.src = null;
this._previewStream.stop();

// .stop() is deprecated
if (this._previewStream.hasOwnProperty('stop')) {
this._previewStream.stop();
} else {
let tracks = this._previewStream.getVideoTracks();
for (let i in tracks) {
tracks[i].stop();
}
}

this._previewStream = null;
if (this.container) {
document.body.removeChild(this.container);
// `document.body.removeChild(this.container);` throws an error on Chrome
// Solution: https://stackoverflow.com/a/42957162/1010548
this.container.parentNode.removeChild(this.container);
}
};

Expand Down