Browse Source

Fixed initial sinkId setting. Can you be set while playing

reviewable/pr190/r10
Samuel Attard 6 years ago
parent
commit
6fe71715e0
  1. 11
      src/inject/GPMInject/playback/audioEQ.js
  2. 11
      src/inject/GPMInject/playback/audioSelection.js

11
src/inject/GPMInject/playback/audioEQ.js

@ -15,8 +15,15 @@ window.wait(() => {
_.forEach(devices, (device) => {
if (device.label === Settings.get('audiooutput')) {
set = true;
setAudioDevice(device.deviceId)
.then(resolve);
let once = true;
console.log('Found Device');
document.querySelector('audio').addEventListener('playing', () => {
if (!once) return;
once = false;
console.log('Play Start');
setAudioDevice(device.deviceId)
.then(resolve);
});
}
});
if (!set) resolve();

11
src/inject/GPMInject/playback/audioSelection.js

@ -13,14 +13,11 @@ Emitter.on('audiooutput:fetch', () => {
});
});
export const setAudioDevice = (id) => {
let count = 0;
export const setAudioDevice = (id, count = 0) => {
return new Promise((resolve, reject) => {
const trySet = setInterval(() => {
document.querySelectorAll('audio')[0].setSinkId(id)
.then(() => { clearInterval(trySet); resolve(); })
.catch(() => { count++; if (count > 10000) { reject(); } }); // eslint-disable-line
}, 50);
document.querySelectorAll('audio')[0].setSinkId(id)
.then(() => { resolve(); })
.catch((oops) => { if (count > 10000) { reject(oops); } else { setAudioDevice(id, count + 1).then(resolve).catch((err) => reject(err)); } }); // eslint-disable-line
});
};

Loading…
Cancel
Save