Stream audio with pulseaudio
I use spotify now
So I have my music collection in my laptop hard drive, I wanna be able to play and control music everywhere.
For changing the current track, I use Emacs with emms and mpv, I don't have the need to use mpd to control to my music, I can just mosh to my machine and use emacsclient.
But how to hear the music? For me I use a solution based on pulseaudio and ffmpeg, it's a hack but it works for now.
The two machines are connected to a wireguard based VPN (did I mention how much I love wireguard?):
- The work machine has address 10.1.1.2
- My machine has address 10.1.1.3 and plays music
So first I create a null sink called
pactl load-module module-null-sink sink_name=remote
Then I stream audio using mp3lame codec to the other computer (btw data is pcms16le so if you want to transmit that good luck but that will need a lot of bandwidth)
(I don't have firewalls so this is easy)
ffmpeg -f pulse -i "remote.monitor" -acodec libmp3lame -ab 128k -ac 2 -f mp3 "udp://10.1.1.2:1337"
Then I change the output mpv to the new sink.
I just play the stuff using ffplay
ffplay -nodisp -ac 2 -bufsize 3000k -ab 128k -acodec mp3 -f mp3 -i "udp://localhost:1337"