Not all Androids may have a PCM output device in /dev
, as Vi0's answer requires.
A more general solution is to setup Pulse to stream system audio to a TCP port on your device. Then you can use Simple Protocol Player or PulseDroid in your Android environment to play the stream.
To eliminate chop/lag in VLC, MPlayer, and Audacity, it was necessary for me to choose ALSA as the output device and Pulse as the mixer (in these programs' options).
Steps I used on my Amazon Fire 7" 2015 / CM12 / Debian Wheezy chroot:
- Install pulseaudio in the chroot:
sudo apt-get install pulseaudio
.
- As suggested by a comment on meefik's github, I removed the line
load-module module-console-kit
from the file /etc/pulse/default.pa
.
- Run
pactl list | grep 'Name\|Description'
and identify a module that monitors system audio. I successfully used 'Dummy Output Monitor' named auto_null.monitor
.
- Write a corresponding shell script
pashare
as follows (credit to AlexAndersan on SuperUser):
#!/bin/sh
case "$1" in
start)
$0 stop
pulseaudio --start
pactl load-module module-simple-protocol-tcp rate=44100 format=s16le channels=2 source=auto_null.monitor record=true port=8000
;;
stop)
killall pulseaudio
pactl unload-module `pactl list | grep tcp -B1 | grep M | sed 's/[^0-9]//g'`
;;
*)
echo "Usage: $0 start|stop" >&2
;;
esac
Make sure the rate
and port
arguments match your settings in Simple Protocol Player (on the Android side). PulseDroid demands rate=48000
, which means higher throughput, and could possibly introduce chop/lag.
I added the pulseaudio --start
and killall
lines because pulse would not start automatically in my chroot.
- Make the script executable and run it:
chmod 755 pashare
sudo mv pashare /usr/local/bin/
pashare start
Configure your chroot media players to output to ALSA, with Pulse mixer. I had to set this manually, to eliminate choppy audio:
VLC: In Tools->Preferences->Audio, set Output module: ALSA audio output
, and Device: Playback/recording through the PulseAudio sound server
.
GNOME MPlayer: In Edit->Preferences->Player, set Audio Output: ALSA
.
In Android, start Simple Protocol Player or PulseDroid on IP address 127.0.0.1
(loopback) and set the other option(s) to match your pashare
script.
Note that Android treats the app like a music player, and will kill it if another app tries to play music, or if it decides to free up the CPU. There are probably workarounds for this.