Loading...
const stream = await navigator.mediaDevices.getUserMedia({ audio: true, video: true });
audio.srcObject = stream;try {
const stream = await navigator.mediaDevices.getUserMedia({ audio: true });
audio.srcObject = stream;
} catch (err) {
if (err.name === 'NotAllowedError') showPermissionHint();
}Request only the microphone and handle a denied permission instead of leaving the promise rejection unhandled.
try...catch and handles 'NotAllowedError' when permission is denied.{ audio: true } without video.navigator.mediaDevices undefined?The API exists only in secure contexts, so the page must be served over HTTPS or from localhost.
getUserMedia()?Call stop() on every track: stream.getTracks().forEach((t) => t.stop()). The recording indicator turns off once all tracks stop.
Yes. List devices with enumerateDevices() and pass { audio: { deviceId: { exact: id } } } to getUserMedia().