How to delete track from MediaStream webcam and "stop"?

I am trying to remove a track from MediaStream. MediaStream.removeTrack() removes the track from the stream, but the camera light remains on the display, indicating that the camera is still active.

https://developer.mozilla.org/en-US/docs/Web/API/MediaStreamTrack?redirectlocale=en-US&redirectslug=DOM%2FMediaStreamTrack

This refers to the stop() method, which I suppose will completely stop the camera. In chrome, however, I get "Object MediaStreamTrack has no method 'stop'"

Is there a way around this, or do I need to stop the entire stream and then recreate it using tracks that I don't want to leave? For example, I want to delete a video track while the audio track is still there.

+4
source share
3 answers

MediaStreamTrack.stop() now added in Chrome.

MediaStream.stop() deprecated in Chrome 45.

You must use MediaStream.getVideoTracks() to get the video tracks and stop the track using MediaStreamTrack.stop()

+7
source

You need to call stop () in MediaStream, not MediaStreamTrack.

Take a look at simpl.info/gum . On the console, call stream.stop() : recording stops, and the camcorder's indicator goes off.

+2
source

It seems that the right way to deal with this problem is to stop your MediaStream , recreate (and reconnect) it as audio only, and then renegotiate the PeerConnection session. Unfortunately, Firefox does not currently support a revised average session.

Thus, the only viable hack is also to recreate PeerConnection with the new MediaStream , as suggested here (see "Adding a video in the middle of -Call").

0
source

Source: https://habr.com/ru/post/1496426/


All Articles