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

getusermedia, javascript, webrtc

Solution

`MediaStreamTrack.stop()` is now added to the Chrome.

`MediaStream.stop()` is deprecated in Chrome 45.

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

Problem

I'm trying to remove a track from a MediaStream. `MediaStream.removeTrack()` removes the track from the stream, but the camera light is left on indicating that the camera is still active. https://developer.mozilla.org/en-US/docs/Web/API/MediaStreamTrack?redirectlocale=en-US&redirectslug=DOM%2FMediaStreamTrack This references a `stop()` method which I suppose would stop the camera completely, In chrome however I get `"Object MediaStreamTrack has no method 'stop'"` Is there a way around this or do I have to stop the whole stream and then recreate it with the tracks I don't want gone? As an example, I want to remove the video track while the audiotrack is still there.

Original source