Sharing Local Music with Friends

The third decade of twenty-first century is strange—people figured out how to make matrices write stories in the style of King James Bible, but there’s no easy way to send a large file to your friend1.

Yeah, magic-wormhole, etc, etc, but I should be able to right click on a file and select “send to Ian”. xkcd 949 isn’t going away any time soon.

Another thing you can’t easily do is to listen to your local music with your friend over the internet. Your only options are either some janky Discord bot that distorts the sound and can’t find any non-popular song, or two subscription on some streaming service that has the song you want to play.

But this is 2023, of course there’s some open source program, that will work brilliantly with just eight hours of fiddling. Here’s how to fiddle said program and a bit more in 30 minutes.

Architecture

You play music on your computer, the audio stream is captured by a program, that program sends the audio stream to a server. Your friend opens a web page which contains a html audio tag, which streams music from that server.

Server

First, you need a server, ie, any computer that has an publicly accessible ip. On that server, install icecast2. On debian, it’s as simple as

apt install icecast2

Then, change the default password and listening port, the config file is at /etc/icecast2/icecast.xml. You don’t need to touch anything else.

Now you can start icecast2 and forget about it, the command on Debian is

systemctl start icecast2

Local streamer

Now, install butt. If you use Mac, you can also use LadioCast.

In butt, open Settings—main—Server Settings—Add, and configure according to your server:

Feed audio output

Now you need to feed os audio output into your local streamer. Follow this article: How to broadcast music files with butt on macOS. Then butt will stream it to icecast2, and whoever listening on <server address>:<port>/xxx will be able to hear what you are playing locally.

A web page

Your friend needs a music player that supports streaming mp3. Or, better yet, you can host a web page that has a html audio tag that streams audio on <server address>:<port>/xxx. Then your friend only need to visit that web page. I’ve written a web page like that, you can find the kit here: uikit. You need to change the title in index.html, and change the address in script.js to your server’s address.

A screenshot of the web page
The web page looks like this

Additionally, I wrote two scripts that uploads the meta data of the currently playing song to your server, so the web page can show the title, artist, album cover, etc. There are two scripts, itunes.sh and spotify.sh, for each app. Change the server address in them and run them locally when you play the music. The scripts are incredibly dumb, and they only work on Mac, but they work ;-)