Answer the question
In order to leave comments, you need to log in
How to disable the video stream and make the camera available?
Good afternoon. There is a task in an application that broadcasts a stream with getUserMedia, to make a button that will stop the stream and make the camera available in other applications. In the myStream object that the function returns on success, I found the stop() method, but it does not work. Please tell me the solution.
angular.module("App", [])
.controller("defaultCtrl", function ($scope, $timeout) {
navigator.getUserMedia = function (constraints, cb, errcb) {
navigator.mediaDevices.getUserMedia(constraints)
.then(cb, errcb);
}.bind(navigator);
navigator.getUserMedia({
video: true,
audio: true
}, angular.bind(this, function (myStream) {
const stream = document.querySelector('#localVideo');
$scope.streamVideo = myStream.getTracks()[0]
stream.srcObject = myStream;
}), angular.bind(this, function (error) {
console.error(error);
}));
})
.directive('ngStop', function(){
return function(scope, element, attrs){
const stream = document.querySelector('#localVideo');
const button = document.getElementById('btn')
button.addEventListener('click', function(){
scope.streamVideo.stop();
})
}
})
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question