My mobile music player is often missing the files I want to hear right now if I'm under way because my music collection is too big to fit on it.
Long time ago I used
gnump3d which seems to be unmaintained in
Debian for quite some time and then I often listened to some live streams, network connections are available nearly everywhere.
But I always wanted my own live stream with music I want to hear. There are several solutions out there for this task but they all require the creation of a playlist before the streaming starts.
Fortunately
mpd provides the possibility to define different output targets and also one for streaming to a shoutcast or compatible server like
icecast.
So after
apt-get install mpd icecast2 (on a Debian box) you have to edit
/etc/mpd.conf
There is not much to do, be sure to set
music_directory to the place your music is located and the configure the output part.
Add the following to your mpd.conf and adapt some values:
audio_output {
type "shout"
name "foobar stream"
port "8000"
host "localhost"
format "44100:16:2"
mount "/stream.ogg"
password "somepass"
quality "2"
user "source"
}
The
type defines that this output will be streamed to a shoutcast target. The
name will be displayed by the client you use to play your stream. 8000 is the
port icecast2 will listen on
host "localhost" (in this example the icecast2 server is on the same host).
format specifies the audio format of the stream, the first number is the sample rate in
Hz, the second number is the number of bits per sample and the last number defines the number of channels (2 is stereo here). Those values should work for most of you.
mount specifies the path under which the stream is available later from the server root, in this example http://localhost:8000/stream.ogg.
quality defines the ogg encoding "quality". You can also specify the bitrate instead of it. The
user and
password values are used to authenticate mpd at the source input for icecast2.
There seems to be a bug in the 0.13 release (which is also in Debian) of mpd that prevents this from working. I don't know the details about this bug but adding
audio_output {
type "alsa"
name "fake out"
driver "null"
}
fixes it.
Make sure to set
START_MPD=true in /etc/default/mpd to enable mpd.
That's all that needs to be done for mpd.
The next step is to edit
/etc/icecast2/icecast.xml.
The default configuration nearly ready to use. Configure the authentication part:
<authentication>
<source-password>somepass</source-password>
<admin-user>admin</admin-user>
<admin-password>someadminpass</admin-password>
</authentication>
The source password is the one we specified in the mpd configuration. This is needed to authenticate mpd with icecast. source is the default user name icecast uses here. Additionally we define an admin-user that can be used to add users to icecast later because we want to protect the stream by a username and a password.
Then set
<hostname>you.somehost.org</hostname>
.
This hostname is used to generate URLs in icecast that a user receives.
Because we want a very simple authentication for the stream we need to add some options for the mount (/stream.ogg):
<mount>
<mount-name>/stream.ogg</mount-name>
<max-listeners>1</max-listeners>
<authentication type="htpasswd">
<option name="filename" value="/etc/icecast2/htpasswd"/>
<option name="allow_duplicate_users" value="0"/>
</authentication>
<on-connect>/home/icecast/bin/stream-start</on-connect>
<on-disconnect>/home/icecast/bin/stream-stop</on-disconnect>
</mount>
I think the xml tags are pretty much self-explanatory. Keep in mind to set the filename to a location the icecast daemon has access to, that's why I used /etc/icecast2. Then you can add users with
htpasswd or using the web interface on port 8000 and add a user there.
The last thing to do is to adjust the
<alias source="/" dest="/status.xsl"/> setting. Change status.xsl to auth.xsl people need to authenticate if they connect to the web interface before seeing the stream information.
Now you can login via ssh on your home server and use your favorite mpd client to configure playlists on the fly, I use
ncmpc for this. Of course the authentication is not secure, people who sniff your traffic can see your login data.
One thing to keep in mind is to restart mpd after restarting icecast otherwise mpd will hang and not continue to stream, this seems to be a bug.
After routing through your NAT, you should be able to play your stream via http://you.somehost.org:8000/stream.ogg.