'How can I use a virtual audio sink on an android emulator in headless mode? Getting pulseaudio init error when launching emulator

I have a virtual sink on my host machine. pulseaudio is running as a system wide daemon. When trying to launch an emulator with the follow command:

emulator -avd emulator -no-window

I get the following output:

pulseaudio: Failed to initialize PA contextCould not init 'pa' audio driver

If I were to exclude -no-window flag, then it works without issue. How can I get my virtual sink to work on a headless android emulator?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source