The removeTrack() method of MediaStreamremoves a MediaStreamTrack from a stream. Learn the MDN pattern that empties a stream, removing only the camera while keeping the mic, pairing with addTrack(), and the difference between removeTrack() and track.stop()—with five examples and try-it labs.
01
Kind
Instance method
02
Parameter
track
03
Returns
undefined
04
Effect
detach track
05
Use case
MDN empty
06
Status
Baseline widely
Fundamentals
Introduction
A MediaStream holds references to MediaStreamTrack objects. When you compose streams manually with addTrack() or copy tracks into a new stream, you may later need to detach a track without destroying it. removeTrack(track) removes that reference from the stream’s track set.
MDN’s example captures audio and video with getUserMedia, copies tracks into a new MediaStream, then removes both tracks—leaving getTracks() as an empty array. Important: removeTrack() does not call stop() on the track; the hardware may still be active until you stop it separately.
💡
Beginner tip
To fully release a camera or mic, call track.stop() after (or instead of) removing it from the stream.
Concept
Understanding MediaStream.removeTrack()
An instance method that removes one track from this stream’s track set.
Parameters — track: a MediaStreamTrack currently in the stream.
Return value — undefined (none).
Effect — track is no longer listed by getTracks() on this stream.
Not the same as stop — the track object may still be live after removal.
MediaStream.removeTrack() is marked Baseline Widely available on MDN (since September 2017). Logos use the shared browser-image-sprite.png sprite from this project.
✓ Baseline · Widely available
MediaStream.removeTrack()
Removes a MediaStreamTrack from the stream. Returns undefined.
UniversalWidely available
Google ChromeFull support · Desktop & Mobile
Full support
Mozilla FirefoxFull support · Desktop & Mobile
Full support
Apple SafariFull support · macOS & iOS
Full support
Microsoft EdgeFull support · Chromium
Full support
OperaFull support · Modern versions
Full support
Internet ExplorerNo MediaStream.removeTrack
Not supported
MediaStream.removeTrack()Excellent
Bottom line: Call removeTrack(track) to detach a track from a MediaStream without necessarily stopping it.
Wrap Up
Conclusion
MediaStream.removeTrack(track) detaches a MediaStreamTrack from a stream and returns undefined. MDN’s example removes audio and video until getTracks() is empty. Pair with addTrack() for manual composition, and call track.stop() when you need to release hardware.
removeTrack(track) removes a MediaStreamTrack from the stream's track set. The track parameter must be a MediaStreamTrack object that is currently in the stream.
No. MDN marks MediaStream.removeTrack() as Baseline Widely available (since September 2017). It is not Deprecated, Experimental, or Non-standard.
undefined. MDN documents no return value. Use getTracks() afterward to see what remains in the stream.
No. removeTrack() only detaches the track from this stream. The track object may still be live. Call track.stop() separately if you want to end the camera or microphone hardware.
addTrack(track) adds a track to the stream. removeTrack(track) removes it. They are inverse operations for composing streams manually.
After getUserMedia, copy tracks into a new MediaStream, then remove the video and audio tracks—getTracks() returns an empty array.
Did you know?
MDN’s removeTrack() example leaves newStream.getTracks() as an empty array—but the original MediaStreamTrack objects may still be live until you call stop() on them.