S
S
Sergey2019-06-06 14:42:13
JavaScript
Sergey, 2019-06-06 14:42:13

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

1 answer(s)
V
Vladimir, 2019-06-07
@Banjamin

https://stackoverflow.com/questions/11642926/stop-...
stream.getTracks().forEach(track => track.stop())

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question