16

How to completely kill the WebRTC media stream?

MediaStream.stop() is not working anymore.

Testing in Chrome 47, Mac OS 10.11.

2 Answers 2

45

Use stream.getTracks().forEach(track => track.stop());.

stream.stop() was deprecated.

2
  • 4
    Is it possible to launch tracks again once they are stopped?
    – igorpavlov
    Jan 23, 2016 at 19:59
  • 4
    No, stopped tracks are ended.
    – jib
    Jan 23, 2016 at 23:46
0

For all browsers

if (microphone_data.media_stream) {
    microphone_data.media_stream.getTracks().forEach(function (track) { track.stop(); });
}
2
  • 3
    What is microphone_data and what is media_stream? Those are not defined in the HTML5 media API.
    – Dai
    Nov 13, 2020 at 8:11
  • @Dai: Those are his variables. media_stream would be an instance of the HTML5 MediaStream Jan 4 at 7:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.