mirror of
https://gitee.com/shuto/cordova-plugin-camera.git
synced 2025-04-22 12:46:22 +08:00
CB-10502 Fix camera plugin exception in Chrome when click capture.
The MediaStream.stop() method has been deprecated as of Chrome 47. We were using it, and it was generating an exception. If stop() method is not found, instead stop each individual track (the new way of doing it).
This commit is contained in:
parent
06fcbf05a2
commit
e48a7e5c5c
@ -37,7 +37,7 @@ function takePicture(success, error, opts) {
|
|||||||
var imageData = readerEvent.target.result;
|
var imageData = readerEvent.target.result;
|
||||||
|
|
||||||
return success(imageData.substr(imageData.indexOf(',') + 1));
|
return success(imageData.substr(imageData.indexOf(',') + 1));
|
||||||
}
|
};
|
||||||
|
|
||||||
reader.readAsDataURL(inputEvent.target.files[0]);
|
reader.readAsDataURL(inputEvent.target.files[0]);
|
||||||
};
|
};
|
||||||
@ -65,13 +65,20 @@ function capture(success, errorCallback) {
|
|||||||
var imageData = canvas.toDataURL('img/png');
|
var imageData = canvas.toDataURL('img/png');
|
||||||
imageData = imageData.replace('data:image/png;base64,', '');
|
imageData = imageData.replace('data:image/png;base64,', '');
|
||||||
|
|
||||||
// stop video stream, remove video and button
|
// stop video stream, remove video and button.
|
||||||
|
// Note that MediaStream.stop() is deprecated as of Chrome 47.
|
||||||
|
if (localMediaStream.stop) {
|
||||||
localMediaStream.stop();
|
localMediaStream.stop();
|
||||||
|
} else {
|
||||||
|
localMediaStream.getTracks().forEach(function (track) {
|
||||||
|
track.stop();
|
||||||
|
});
|
||||||
|
}
|
||||||
video.parentNode.removeChild(video);
|
video.parentNode.removeChild(video);
|
||||||
button.parentNode.removeChild(button);
|
button.parentNode.removeChild(button);
|
||||||
|
|
||||||
return success(imageData);
|
return success(imageData);
|
||||||
}
|
};
|
||||||
|
|
||||||
navigator.getUserMedia = navigator.getUserMedia ||
|
navigator.getUserMedia = navigator.getUserMedia ||
|
||||||
navigator.webkitGetUserMedia ||
|
navigator.webkitGetUserMedia ||
|
||||||
@ -85,7 +92,7 @@ function capture(success, errorCallback) {
|
|||||||
|
|
||||||
document.body.appendChild(video);
|
document.body.appendChild(video);
|
||||||
document.body.appendChild(button);
|
document.body.appendChild(button);
|
||||||
}
|
};
|
||||||
|
|
||||||
if (navigator.getUserMedia) {
|
if (navigator.getUserMedia) {
|
||||||
navigator.getUserMedia({video: true, audio: true}, successCallback, errorCallback);
|
navigator.getUserMedia({video: true, audio: true}, successCallback, errorCallback);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user