Skip to content

Commit

Permalink
Release camera when stop is called
Browse files Browse the repository at this point in the history
  • Loading branch information
Laszlo Radics committed Dec 17, 2014
1 parent 460e406 commit 655bc64
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/camera_access.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@

define(function() {
"use strict";

var streamRef;

/**
* Wraps browser-specific getUserMedia
* @param {Object} constraints
Expand All @@ -12,6 +13,7 @@ define(function() {
*/
function getUserMedia(constraints, success, failure) {
navigator.getUserMedia(constraints, function(stream) {
streamRef = stream;
var videoSrc = (window.URL && window.URL.createObjectURL(stream)) || stream;
success.apply(null, [videoSrc]);
}, failure);
Expand Down Expand Up @@ -89,6 +91,12 @@ define(function() {
return {
request : function(video, callback) {
request(video, callback);
},
release : function() {
var tracks = streamRef && streamRef.getVideoTracks();
if (tracks.length)
tracks[0].stop();
streamRef = null;
}
};
});
3 changes: 3 additions & 0 deletions src/quagga.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,9 @@ function(Code128Reader, EANReader, InputStream, ImageWrapper, BarcodeLocator, Ba
},
stop : function() {
_stopped = true;
if (_config.inputStream.type == "LiveStream") {
CameraAccess.release();
}
},
onDetected : function(callback) {
Events.subscribe("detected", callback);
Expand Down

0 comments on commit 655bc64

Please sign in to comment.