MPD + Icecast = Local Network Radio

Valshak's picture
For a while I've used the browser-based UI called Ampache to stream my music files from my server to the computer I am currently on. This works well considering you only need to be connected to my network, have a web browser and a media player that can handle streaming. But I've been thinking recently that I'd simply like to be able to 'tune-in' to my music, just like it was a radio station (minus commercials of course). So I've been searching/thinking of ways to accomplish this and I think I've found the path I want to take. MPD streams audio to the Icecast server which, in turn, 'broadcasts' it to the network for anyone to connect to. This is an awesome system that, I feel, works wonders. Currently I have: MPD [Music Player Daemon], ncMPC,[NCurses Music Player Client] and Icecast installed on the server. I'll try to break the setup processes down as best I can and hopefully it can be followed (I felt fairly helpless when I was trying to get this working myself).

NOTE: My server is running Gentoo so I'll be speaking from that distrobutions point-of-view.

MPD::
  1. Install MPD: #emerge mpd -- Gentoo does a really nice job in initial setup and configuration of MPD, which is nice. This means that Gentoo creates a new user 'mpd' in the group of 'audio' and makes MPD's directories owned by that user.
  2. Configure MPD: #nano /etc/mpd.conf
    •    Set 'music_directory' to "/exact/path/to/music"
    •    Set 'bind_to_address' to "IP.of.server"
    •    Where 'name' is 'shout', uncomment: 'audio_output {, type, name, host, port, mount, password, quality, format, user and the closing }'
    •    Set 'name' to whatever you want the 'station' to be called
    •    Set 'host' to "IP.of.server"
    •    Other parts of this section will be revisited when we configure Icecast.
    •    Create a database of your music by running:    #/etc/init.d/mpd create-db -- You will know that all is well if you see output in your terminal mentioning any music files found being added to the database.
===========================
Icecast::
  1. Install Icecast: #emerge icecast -- Once again Gentoo saves some time when it comes to configuring by giving you a fairly usable initial setup.
  2. Configure Icecast: #nano /etc/icecast2/icecast.xml
    •    NOTE: Most of the stuff in this file is commented-out and thankfully those are not needed. Anything that is inbetween <!-- and --> is a comment and will not be 'seen' by Icecast.
    •    Under 'Authentication' set 'source-password', 'relay-password' and 'admin-password' to something other than 'hackme' and preferably each one different. Whatever you choose for your 'source-password' needs to be what 'password' is in the mpd.conf file.
    •    Set 'hostname' to 'IP.of.server'
===========================
Final Step::
  1. Starting the services: #/etc/init.d/icecast start && /etc/init.d/mpd start
  2. Connecting the services: -- Here's the part where a few choices arise for you, the user, in how to interact with MPD remotely.
    •    Sonata - A GTK-based client for MPD. It has several awesome features like lyric and album art retrieval, the ability to have internet-radio stations saved and accessible with a simple double-click, and of course the ability to browse your local collection of music and put it into a playlist.
    •    Ncmpc - A ncurses-based client for MPD that is for strict usage from the command line. There're no bells-n-wistles on this baby, just the basics. This makes it awesome for remote use.
    •    VLC - VLC is just an awesome all around media player available for both Windows and Linux. It has a simple interface but it's packed full of features and abilities.
===========================
The Process:: -- Alright, so you've got MPD and Icecast running and configured on your server. Now, following much the same processes you must get MPD installed and configured on your local system.

Quickly --
  1.    Install by #emerge mpd
  2.    Configure by:
    •    Set 'music_directory' to '/exact/path/to/music/'
    •    This time where 'name' is whatever your system uses for a sound system, either 'alsa' or 'oss' uncomment the corresponding 'audio_output {, type, name, device, format and closing }'
    •    Then uncomment the lines beginning with 'mixer_', but make sure they correspond with the 'audio_output' you uncommmented (whether you're using ALSA or OSS).
My prefered way of utilizing this system is to use Sonata. So, to go that route:
  1.    Install by #emerge sonata
  2.    Start it up and you should be greeted by Sonata's preferences.
    •    Set 'Name' to the name of your server.
    •    Set 'Host' to the IP address of your server.
    •    Set 'Port' to '6600'.
    •    Click the '+' and repeat the previous steps but instead about your local computer (ie. it's name and IP).
  3.    Right-click->'Connections' and select your server. Then click on the 'Library' tab, if all is well, you should see your entire music selection that's on your server. Find a folder, right-click and click 'Add'. Clicking on the 'Current' tab will show you your current playlist, which should have the contents of whatever folder you just chose from the library. Double-click on a song. You should see the text get bold and the progress bar show up, just like it's playing, but you won't hear anything. Fear not.
  4.    Right-click->'Connections' and select your local computer. Then click the 'Streams' tab. Right-click and click 'New'. Make 'Stream Name' the name from your servers /etc/mpd.conf file's audio_output { } section and make the URL IP.of.server:8000/mpd.ogg.m3u. Double-click on this stream.
  5.    Click on the 'Current' tab and you'll see the URL of the stream as your only item. Double-click on it and after a delay you should hear whatever song you had chosen on the server.
If you want to use Ncmpc and VLC; this is how things go down:
  • First, you'll want to SSH into the server by: $ssh user@IP.of.server. Then run: $ncmpc -c --host="IP.of.server" --port="6600" (the flag '-c' makes ncmpc colorful which is a nice touch I think). In ncmpc the keys: 1,2, and 3 switch between (1) help, (2) playlist editor and (3) file browser. Check the help to learn how to add files to your playlist from the file browser.
  • When you start MPD playing a song or a playlist full of songs it will automatically create an OGG file that it streams all the music to; it does this because of the audio_output{ } section we uncommented in the /etc/mpd.conf file. Within that section is the option 'mount' which is set to, by default, '/mpd.ogg'. This is the file that Icecast uses to share the music that MPD plays.
  • The file mpd.ogg resides in the root directory of your Icecast server. So, to connect to it from another machine you would use the syntax IP.of.server:8000/mpd.ogg.m3u. What's with the .m3u at the end? That's so the client you're using to stream this file knows that it's formatted like a m3u playlist and to read it as such
  • Open VLC and hit ctrl+n, this'll open up the 'Open Network' dialog. Set 'Protocol' to 'HTTP' and 'Address' to 'IP.of.server:8000/mpd.ogg.m3u'. Now, as long as ncmpc on your server is playing a song, you should now be able to hear it locally as it play through VLC. If ncmpc is NOT playing a song, then there will be no mpd.ogg being created so therefore, nothing for Icecast to connect to.
Hope this helps anyone understand how to get their own Icecast server set up. Signing off.