SGG SGG - 14 days ago 10
AngularJS Question

Turn ON/OFF Webcam using AngularJS

I'm using

directive for capturing photos. I'm able to turn OFF the camera. But I'm not able ON it again. Any help would be appreciated.

Here is my current code to stop the camera.

var mStream = null;

$scope.onStream = function (stream) {
// You could do something manually with the stream.
mStream = stream;
};
$scope.stopCamera = function() {
// mStream.stop(); didn't work.
mStream.getTracks()[0].stop();
};
$scope.startCamera = function() {
// mStream.play(); didn't work
// ToDo
};


Thank you

Answer

in webcam directive we have following events

$scope.$on('$destroy', onDestroy);
$scope.$on('START_WEBCAM', startWebcam);
$scope.$on('STOP_WEBCAM', stopWebcam);

in your controller you can use something like this

  $scope.destroyWebcam = function () {
    $scope.$broadcast('$destroy');
  };

 $scope.stopWebcam = function () {
   $scope.$broadcast('STOP_WEBCAM');
 };