How do I set the default soundcard for the root user?

1

I am running raspbian Jessie on my raspi 2. I have an external usb soundcard for my pi. I set it as the default card simply by going to Menu->preferences->Audio Device Settings. This works as expected.

I am writing some code that takes in a file and plays it among other things. The problem is that it must be run with sudo, which then ignores my soundcard and uses the internal card. Is there a way to apply the default soundcard setting to root? I have tried adding root to the audio group, but that didn't help.

Thanks!

Cole

Posted 2016-04-18T22:35:45.380

Reputation: 11

What program are you using for playing? Do both users need to share the sound card? – CL. – 2016-04-19T06:35:03.450

I don't know raspbian, but on Ubuntu (also a Debian derivative) I would use the menu editor to find what is launched when Audio Device Settings is run, then run it under sudo. If this doesn't work I would log into the root account and set the audio from there. – AFH – 2016-04-19T11:14:00.900

@CL. I am using gstreamermm c++ wrappings for gstreamer. Yes, both my user (pi) and root need to use the soundcard. I don't need them to both be using the soundcard at the same time, I just need root to use it instead of the internal one. – Cole – 2016-04-19T17:10:50.117

You'll have to find out how gstreamer is configured (PulseAudio? ALSA?). – CL. – 2016-04-19T17:12:43.647

@CL. There is an element called autoaudiosink that scans all possible sinks and chooses what it thinks is best. I should probably go ahead and switch that to pulseaudiosink since that was my plan all along. Does pulseaudio use completely separate configurations from alsa? – Cole – 2016-04-19T17:18:41.967

@CL. link It looks like this sink allows you to set the device specifically. I will try that today or tomorrow and update this issue. Thanks for getting me thinking in the right direction ;)

– Cole – 2016-04-19T17:20:52.340

No answers