4

To link to SHOUTcast/HTTP internet radio streams, traditionally you would link to a playlist file, such as an M3U or PLS. From there, the browser would launch the audio player registered to handle the playlist. This works great on any PC, Palm, Blackberry, and iPhone.

This method does not work in Android without installing extra software. Sure, Just Playlists or StreamFurious can handle it just fine, but I am assuming there has to be a way to invoke the audio or video player commonly installed by default on Android installations.

By default, no audio player is capable of handling M3U or PLS. The player seems to open it, but says "Unsupported Media Type".

To make this more annoying, the browser is capable of streaming MP3 audio over HTTP, simply by opening a link to an MP3 file. I have tried simply linking directly to the MP3 stream hosted by SHOUTcast, which should end up in the same result, but SHOUTcast detects "Mozilla" in the user-agent string, and instead of sending the stream, it sends the information page for the station.

How should I link to a SHOUTcast stream on Android, from a normal mobile site, without using extra applications?

Brad
  • 146,404
  • 44
  • 300
  • 476
  • 1
    There is no single "audio or video player commonly installed by default on Android installations". The one from the Android open source project does not support playlists, at least through Android 2.3. According to the preview SDK, in Android 3.0, "Applications can now pass an M3U playlist URL to the media framework to begin an HTTP Live streaming session." This means that the Android open source project media player app *might* support playlists, though we are a couple of weeks from finding out. – CommonsWare Feb 13 '11 at 23:43
  • Thanks CommonsWare for your insight. When I open "Music" on my phone, and any other Android-running phone I have seen, that opens an audio player, and it appears the same on every phone I have seen. Is that the audio player you are referring to? Does it have a specific name? What about the browser when I open "Internet".. does it have a name? I understand that these aren't available on *every* Android device, but again, I am trying to target the most common. When I open an MP3 in that browser, it starts streaming it. Is this a feature of the web browser, or something else? – Brad Feb 14 '11 at 02:14
  • 1
    The Android Open Source Project (AOSP) includes a number of standard apps, including the Music player. The source for it is here: http://android.git.kernel.org/?p=platform/packages/apps/Music.git;a=summary . When the browser opens MP3 or other content, it does not run a program by name but asks Android's Intents framework to handle it. It effectively tells the OS "Give this data to a program that can handle the MIME type 'audio/mpeg'". See http://developer.android.com/guide/topics/intents/intents-filters.html, especially the "Data" section. – Reuben Scratton Feb 17 '11 at 15:58

4 Answers4

3

As noted in the comments, what you're asking is impossible, at least until 3.0 comes out and even then it'll be a long time before the functionality is on most devices. The 'without extra apps' constraint is far too limiting. Here are some alternatives that violate this constraint that I urge you to consider instead:

  • Ask users to install an app
    Yes it's not what you want, but it's the easiest thing to do. Just Playlists (as you've discovered) would be a good one to recommend.

  • Use flash
    Not everyone has flash, but for those that do you can embed a flash widget to play the playlist. I found one that sounds like it'll work just from a quick google. Does SHOUTcast have it's own flash player?

  • Wait
    Basically your only other option, since this functionality just isn't there in Android, yet.

fredley
  • 29,323
  • 39
  • 131
  • 223
  • Thanks fredley, I was afraid those were my only options, and I have considered all three. In fact, I am halfway through building a Flash player for it. It's really frustrating that devices 5+ years old support a simple M3U right out of the box, and the default players in Android don't. I haven't given up yet however. I am currently experimenting with forcing the SHOUTcast server to send audio/mpeg despite what the user agent string is. If I can get that to work, then there is hope. Maybe... – Brad Feb 17 '11 at 17:41
1

A solution for all Android! (tested on 2.1 and later)

It turns out that this is possible. For Android, rather than linking to a playlist like you do on other platforms, you simply link directly to the stream. (This seems to be what Reuben Scratton was getting at in his comment. I wish I had seen his comment earlier!)

The browser will connect to the stream, detect the Content-Type, and then decide to pass it off to the default media player if it can handle it. The media player will then buffer and begin playback.

Note that you have to do quite a bit of hacking on SHOUTcast if you want this to work, as Android requires a valid HTTP resource, which SHOUTcast does not provide. Also note that chunked encoding doesn't seem to work on Android 2.2 and earlier.

As a side note, if you don't feel like writing your own code for this, I have implemented streaming to Android in AudioPump, a streaming media server I am working on.

Brad
  • 146,404
  • 44
  • 300
  • 476
1

What kind of stream does you M3U file contain?

You can skip the M3U and set your datasource directly to a rtsp stream for example.

mediaPlayer.setDataSource("rtsp://xxx/stream.stream");

Works perfectly

Don't forget to run it in a different thread.

Buhake Sindi
  • 82,658
  • 26
  • 157
  • 220
Fredrik
  • 1,214
  • 11
  • 14
-1

Finally found a solution! Use Opera web browser, which will prompt to save the m3u file. Then launch justplaylists. Works like a charm on my HTC Incredible 2

Ted
  • 1