flecs icon indicating copy to clipboard operation
flecs copied to clipboard

[Feature Request] Select audio output device

Open churchymayer opened this issue 4 years ago • 4 comments

It would be nice if I could set a custom audio output device

churchymayer avatar Feb 18 '21 19:02 churchymayer

Its usually the operating system's job to do that, for example:

Windows 10 lets you define input/output devices for each application separately via “App Volume And Device Preferences” can be opened with command ms-settings:apps-volume (You can set that as shortcut target)

See some random tutorial And random screenshot of that feature:

Araxeus avatar Apr 01 '21 13:04 Araxeus

Actually it's not so usual... Microsoft added this functionality to Windows Media Player with Windows 7 release and Windows 8.1 audio settings still can't do that. Appunti01

There's an extension for Chrome called AudioXout addressing this issue: it doesn't remember device choice (it should, but doesn't work) and requires only microphone permissions; maybe it could be ported as a plugin for this app. Appunti02

fedemox avatar Jul 04 '22 10:07 fedemox

If anyone want to make a plugin for this, should probably use HTMLMediaElement.setSinkId()

could use inspiration from https://github.com/rain-fighters/AudioPick

Araxeus avatar Jul 05 '22 16:07 Araxeus

I needed this feature, and implement the simplest dumb plugin with hardcoded deviceId. For anyone that need this, just create a new directory named "pref-audio-out-device" at "plugins" inside create a file named "front.js" with this content:

module.exports = () => {
	document.addEventListener('apiLoaded', apiEvent => {
		changeToPrefAudioOutDevice();
		navigator.mediaDevices.ondevicechange = (e) => {
			changeToPrefAudioOutDevice();
		};
	}, { once: true, passive: true })
};

function changeToPrefAudioOutDevice() {
	const prefAudioOutDeviceId = '74b147ea818349756def2d6dae3a5422f8be7f0ef7b91749f61cfbe7a83730fe'; //TODO load from plugin options

	navigator.mediaDevices.enumerateDevices().then((devices) => {
		devices.forEach((device) => {
			console.log(`${device.kind}: ${device.label} id = ${device.deviceId}`);
			if (device.kind === 'audiooutput' && // device type is audio output
				device.deviceId === prefAudioOutDeviceId && // preferred audio out device is connected
				document.querySelector('.video-stream,.html5-main-video').SinkId !== prefAudioOutDeviceId) { // preferred audio out device is not already set
					document.querySelector('.video-stream,.html5-main-video').setSinkId(device.deviceId); // set preferred audio out device
			}
		});
	}).catch((err) => {
		console.error(`${err.name}: ${err.message}`);
	});
}

'74b147ea818349756def2d6dae3a5422f8be7f0ef7b91749f61cfbe7a83730fe' is the hardcoded deviceId of My preferred audio out device :) See the console log for a list of your devices.

The navigator.mediaDevices.ondevicechange is not working, only change at app start :(

Testing with git version, with kde plasma 5.24.6

Azureit avatar Aug 27 '22 19:08 Azureit

Just want to express my interest in this as well. I tried what Azureit explained but had compilation failures which I don't know how to diagnose/fix. Hoping this will be implemented at some point, since setting it in Windows' sound mixer doesn't persist after rebooting (edit: even restarting the application).

akumenon avatar Dec 30 '22 20:12 akumenon

Just want to express my interest in this as well. I tried what Azureit explained but had compilation failures which I don't know how to diagnose/fix. Hoping this will be implemented at some point, since setting it in Windows' sound mixer doesn't persist after rebooting.

Try going to Window Settings > Audio (maybe under Devices) > App Volume and selecting audio device. The names might be different (I'm not on Windows now so I can't check), but I know that there's an option in Settings that persists even after reboot. I've used it before in both Win 10 and 11.

Zo-Bro-23 avatar Dec 31 '22 02:12 Zo-Bro-23

But +1 for adding this feature to the YTM app.

Zo-Bro-23 avatar Dec 31 '22 02:12 Zo-Bro-23

i also tried azureit mentioned and no success hopefully this does get added

stoicpenguin2234 avatar Jan 20 '23 23:01 stoicpenguin2234

should be pretty easy to do after those:

  1. https://developer.chrome.com/blog/audiocontext-setsinkid/ (Published on Wednesday, January 11, 2023)
  2. https://github.com/th-ch/youtube-music/pull/951 (Merged on Sunday, January 8, 2023)

Anyone want to give it a shot?

Araxeus avatar Jan 22 '23 18:01 Araxeus