Making BackgroundAudioPlayer on Windows Phone 7 work with a Shoutcast stream

Starting with the Microsoft example code for the Background Audio Player, it was less than obvious how to make it work with a Shoutcast stream. If you go to a Shoutcast stream with using a standard HTTP GET request (i.e. from a web browser), you’ll get a web page, giving some details on the stream. The trick to making it actually stream the audio is adding a slash then a semi-colon followed by a MP3 filename. Here is an example using a BassDrive.com stream (paste the full url without the quotes into Quicktime > Open Location or similar in other app, if you paste it into a browser it will either play the audio or if it doesn’t recognise the content type you’ll just see the encoded audio as text filling up your browser window)…

"http://shouthostdirect10.streams.bassdrive.com:8200/; stream.mp3"

Now, if you copy that entire URL into your browser, it will start downloading an MP3 file of the stream instead of serving you the HTML webpage. You can then set it up with something like this…

BackgroundAudioPlayer.Track = new AudioTrack(new Uri("http://shouthostdirect10.streams.bassdrive.com:8200/; stream.mp3"), "Bassdrive", "Bassdrive", "Bassdrive", null, null, EnabledPlayerControls.Pause);

I hope that helps someone.

top