navigator.mediaDevices
.getUserMedia({ audio: true, video: true })
.then((mediaStream) => {
document.querySelector("video").srcObject = mediaStream;
// Stop the audio stream after 5 seconds
setTimeout(() => {
const tracks = mediaStream.getAudioTracks();
tracks[0].stop();
}, 5000);
});MediaStream: getAudioTracks() method / notebook
MediaStream: getAudioTracks() method
Runnable notebook: every JavaScript, HTML and CSS example on this page executes in a sandboxed local frame. Nothing leaves the browser.