2

I'm trying to force a single page that's playing audio through javascript to use a different soundcard from the rest of the browser(from the rest of the system actually). My current understanding is that a browser doesn't access the soundcard sink directly, but delegates to the plugin that wants to play audio. This should theoretically make it possible for javascript to use a different sound sink than flash, or any other plugin. Whether it's actually possible...

Note that this isn't intended to be distributed, I'm only trying to change the output on one computer, through the console or similar.

2 Answers2

4

It's the future and now it is possible! You can gather available output deviceIds using the mediaDevices.enumerateDevices function. Then apply your desired deviceId to an Audio element with setSinkId

const devices = await navigator.mediaDevices.enumerateDevices();
const outputs = devices.filter(({ kind }) => kind === 'audiooutput');
const output = outputs[1]; // Choose a device

const audio = new Audio();
audio.setSinkId(output.deviceId);
audio.play();

All that is left is applying some sound to audio by setting it's src or srcObject field.

Related codepen: https://codepen.io/smujmaiku/pen/oNjBmVj

Note: audio.play() does require some user interaction first.

Also: Check your flags https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/setSinkId

SmujMaiku
  • 141
  • 5
0

Impossible. Maybe in future but for a now Safari, Chrome, FireFox, Opera and rest of browser doesn't have even options in Settings/Preferences to change it. And as You know javascript works in internet browser and are capable to do what they(internet browser) can do.

Now I'm thinkng that there is a chance to change this with Node.js as you can write a package/core hook/external module and be able to somehow change it with javascript but the effect of changing the soundcard will be only on server side client with Node.js + your module.

If You want to change this (beside that You are not able to use javascript and internet browser) you can use Virtual Audio Cable http://en.wikipedia.org/wiki/Virtual_Audio_Cable which is an application for windows.

Similar question Change the audio output device in Firefox

fearis
  • 103
  • 5