Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the option to set a custom 'sinkId' (audio output device) #723

Closed
wants to merge 3 commits into from

Conversation

fartek
Copy link

@fartek fartek commented Mar 20, 2017

I needed this functionality for a project we were building, so I decided to add it to the library. Basically, when you create the Howl object, you add the parameter 'sinkId' and set it to the id of a custom audiooutput device (also set html5 to true). For more info on this: https://developer.mozilla.org/en-US/docs/Web/API/MediaDevices/enumerateDevices

@goldfire
Copy link
Owner

Interesting, I hadn't heard about this until just now. As it stands right now, it would need to be added as its own plugin since the howler.js core needs to have full compatibility between HTML5 and Web Audio. I'd also like to see this get a little less "experimental," so I'll leave this for now and re-asses in the future. Thanks!

@ibc
Copy link

ibc commented Jan 22, 2018

Hi, any update or planning for this feature?
Thanks.

@danjenkins
Copy link

I also need to be able to set this. I wouldnt class this as experimental any longer. Considering forking the project for the time being until we can get this PR merged.

@fartek
Copy link
Author

fartek commented Jul 13, 2018

Hey, I haven't been paying too much attention to this to this thread as we've ended up using my fork. Can anyone comment what's the current state regarding setting sink ids? @goldfire?

@xdumaine
Copy link

@xdumaine
Copy link

xdumaine commented Aug 30, 2018

Here's a little hacky way to make howler's webaudio mode fallback to html5 for playing sounds to alternate sinkIds:

const mediaStreamNode = Howler.ctx.createMediaStreamDestination();
Howler.masterGain.connect(mediaStreamNode);

const devices = await navigator.mediaDevices.enumerateDevices();
const dests = devices.filterBy('kind', 'audiooutput');

const promises = dests.map(async dest => {
  const audio = document.createElement('audio');
  audio.autoplay = true;
  document.body.append(audio);
  audio.srcObject = mediaStreamNode.stream;
  await audio.setSinkId(dest.deviceId);
});

await Promise.all(promises);

Obviously, we'd want to integrate this with the html 5 node in howler, but the fact that this mixes WebAudio with HTML5 would probably cause some issues with howler core.

@fartek fartek closed this Sep 1, 2018
@danjenkins
Copy link

danjenkins commented Sep 10, 2018

@xdumaine this is exactly how I've worked around it before

And yes, the fact that you need to have a html element to set a sink Id sucks and should be fixed within web audio

@n3tman
Copy link

n3tman commented Jul 1, 2019

Thanks for this PR! Helped me understand how to edit the library, since I had the same problem.
Though I had to add some more lines to Sound.prototype methods init and reset:

self._sinkId = parent._sinkId;

You might want to check wavesurfer.js implementation of setSinkID:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants