The getAudioTracks() method of MediaStream returns an array of audio MediaStreamTrack objects in the stream. Learn the MDN getUserMedia timer example that stops the mic, empty arrays for video-only streams, filtering with track.kind, and comparison with getTracks()—with five examples and try-it labs.
01
Kind
Instance method
02
Returns
Track array
03
Filter
kind audio
04
Empty
no mic tracks
05
Use case
Stop mic
06
Status
Baseline widely
Fundamentals
Introduction
A MediaStream can hold both audio and video tracks. When you call getUserMedia({ audio: true, video: true }), the browser usually adds at least one microphone track and one camera track. getAudioTracks() gives you only the audio ones—handy for muting, stopping, or inspecting the mic without touching video.
MDN: the return value is an array where each entry is a MediaStreamTrack with kind === "audio". If there are no audio tracks, you get an empty array []. The order of tracks is not guaranteed and may change between calls.
💡
Beginner tip
Use getAudioTracks()[0] when you expect one microphone—but always check .length first so you do not call .stop() on undefined.
Concept
Understanding MediaStream.getAudioTracks()
An instance method that filters the stream’s track set to audio tracks only.
Parameters — none.
Return value — array of MediaStreamTrack with kind"audio".
Empty array — when the stream has no audio tracks (e.g. canvas video only).
Order — not defined by the spec; may vary between calls (MDN).
MediaStream.getAudioTracks() 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.getAudioTracks()
Returns an array of audio MediaStreamTrack objects in the stream.
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.getAudioTracks
Not supported
MediaStream.getAudioTracks()Excellent
Bottom line: Call getAudioTracks() to list, mute, or stop microphone tracks in a stream.
Wrap Up
Conclusion
MediaStream.getAudioTracks() returns every audio track in a stream as an array. Use it to stop or mute the microphone, count audio inputs, or separate audio from video—MDN’s timer example stops tracks[0] after five seconds while video can continue.
Call stop() on audio tracks when done with the mic
Pair with getVideoTracks() for full stream control
❌ Don’t
Assume track order stays the same between calls
Call tracks[0].stop() without checking length
Expect audio from canvas.captureStream()
Confuse enabled (mute) with stop() (end)
Forget secure-context requirements for getUserMedia
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about getAudioTracks()
List and control microphone tracks in a stream.
5
Core concepts
🎤01
Returns
array
API
🔗02
Filter
kind audio
Rule
📦03
Empty
[] ok
Edge
📄04
MDN
stop mic
Pattern
🎯05
Baseline
since Sep 2017
Status
❓ Frequently Asked Questions
An array of MediaStreamTrack objects whose kind property is "audio". If the stream has no audio tracks, the array is empty.
No. MDN marks MediaStream.getAudioTracks() as Baseline Widely available (since September 2017). It is not Deprecated, Experimental, or Non-standard.
No. MDN documents getAudioTracks() with no parameters. Call it on a MediaStream: stream.getAudioTracks().
No. MDN says the order is not defined by the specification and may change from one call to the next.
getTracks() returns every track in the stream. getAudioTracks() returns only tracks where track.kind === "audio".
After getUserMedia with audio and video, call getAudioTracks()[0].stop() to stop the microphone track—for example after a timer expires.
Did you know?
MDN’s getAudioTracks() example stops only the microphone after five seconds with tracks[0].stop()—the video track can keep running for preview or recording.