Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

How do you get pulseaudio to play sound in a KVM virtual machine (running as root) and your desktop apps (not running as root) at the same time?

It seems that by default, it will only play sound for one user at a time, blocking all others.

For example,

I play some music:

mplayer ~/Music/*

my VM starts with:

kdesu qemu-system-x86_64 -enable-kvm [... disks, network, etc. ...] -soundhw hda

This runs the process as root, with the X display of the user that runs it. And sound doesn't work until mplayer stops.

If run in a root shell instead, I get:

pulseaudio: pa_context_connect() failed
pulseaudio: Reason: Connection refused
pulseaudio: Failed to initialize PA contextaudio: Could not init `pa' audio driver
ALSA lib pcm_dmix.c:1018:(snd_pcm_dmix_open) unable to open slave
alsa: Could not initialize DAC
alsa: Failed to open `default':
alsa: Reason: Device or resource busy
ALSA lib pcm_dmix.c:1018:(snd_pcm_dmix_open) unable to open slave
alsa: Could not initialize DAC
alsa: Failed to open `default':
alsa: Reason: Device or resource busy
audio: Failed to create voice `dac'

And then the VM runs and its sound device looks like it works, but no sound is played.

Then I can stop mplayer, and then the sound can be played from the VM without restarting it.

Then if I start mplayer again, I get errors and no sound:

AO: [pulse] 44100Hz 2ch s16le (2 bytes per sample)
Video: no video
Starting playback...
A:  -0.0 (unknown) of 308.2 (05:08.2) ??,?% 
Audio device got stuck!
A:  -0.0 (unknown) of 308.2 (05:08.2) ??,?% 
Audio device got stuck!
A:  -0.0 (unknown) of 308.2 (05:08.2) ??,?% 
Audio device got stuck!
A:  -0.0 (unknown) of 308.2 (05:08.2) ??,?% 

I believe I can solve this by uninstalling pulseaudio and using ALSA instead, but then I need to reconfigure qemu config and build it from source. I would like to do it by configuring pulseaudio instead, like with a software mixer in ALSA.

share|improve this question

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.