Skip to content

Commit

Permalink
Run prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
hamishwillee committed Jul 11, 2023
1 parent 1de7de8 commit 81e5a03
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions files/en-us/web/api/audio_output_devices_api/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ The permission status can be queried using the [Permissions API](/en-US/docs/Web
Here's an example of using `selectAudioOutput()`, within a function that is triggered by a button click, and then setting the selected device as the audio output.

The code first checks if `selectAudioOutput()` is supported, and if it is, uses it to select an output and return a [device ID](/en-US/docs/Web/API/MediaDeviceInfo/deviceId).
We then play some some audio using the default output, and then call `setSinkId()` in order to switch to the selected output device.
We then play some some audio using the default output, and then call `setSinkId()` in order to switch to the selected output device.

```js
document.querySelector("#myButton").addEventListener("click", async () => {
Expand All @@ -83,23 +83,25 @@ document.querySelector("#myButton").addEventListener("click", async () => {
return;
}

// Display prompt to select device
const audioDevice = await navigator.mediaDevices.selectAudioOutput();
// Display prompt to select device
const audioDevice = await navigator.mediaDevices.selectAudioOutput();

// Create an audio element and start playing audio on the default device
const audio = document.createElement("audio");
audio.src = "https://example.com/audio.mp3";
audio.play();
// Create an audio element and start playing audio on the default device
const audio = document.createElement("audio");
audio.src = "https://example.com/audio.mp3";
audio.play();

// Change the sink to the selected audio output device.
audio.setSinkId(audioDevice.deviceId);
// Change the sink to the selected audio output device.
audio.setSinkId(audioDevice.deviceId);
});
```

Note that if you log the output details, they might look something like this:

```js
console.log(`${audioDevice.kind}: ${audioDevice.label} id = ${audioDevice.deviceId}`);
console.log(
`${audioDevice.kind}: ${audioDevice.label} id = ${audioDevice.deviceId}`
);
// audiooutput: Realtek Digital Output (Realtek(R) Audio) id = 0wE6fURSZ20H0N2NbxqgowQJLWbwo+5ablCVVJwRM3k=
```

Expand Down

0 comments on commit 81e5a03

Please sign in to comment.