Skip to content

Commit

Permalink
Don's ajust audio track if there is no audio track
Browse files Browse the repository at this point in the history
On a M4 Mac Mini, there is no built-in microphone or
camera, so `getAudioTracks()` will always return an
empty array. In this case, we don't need to ajust
sampling rate to 48khz...
  • Loading branch information
StaZhu committed Dec 25, 2024
1 parent c23f961 commit e67f865
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/content/getusermedia/record/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,14 @@ async function startRecording() {
if (mimeType.split(';', 1)[0] === 'video/mp4') {
// Adjust sampling rate to 48khz.
const track = window.stream.getAudioTracks()[0];
const {sampleRate} = track.getSettings();
if (sampleRate != 48000) {
track.stop();
window.stream.removeTrack(track);
const newStream = await navigator.mediaDevices.getUserMedia({audio: {sampleRate: 48000}});
window.stream.addTrack(newStream.getTracks()[0]);
if (track) {
const {sampleRate} = track.getSettings();
if (sampleRate != 48000) {
track.stop();
window.stream.removeTrack(track);
const newStream = await navigator.mediaDevices.getUserMedia({audio: {sampleRate: 48000}});
window.stream.addTrack(newStream.getTracks()[0]);
}
}
}
try {
Expand Down

0 comments on commit e67f865

Please sign in to comment.