Android: Open PLS-File for MediaPlayer includes same streaming link which opens the PLS file?! Error (1,-2147483648)

StackOverflow https://stackoverflow.com/questions/15044958

Question

I'm working at a streaming app for Android and just faceing a strange error. My streaming urls are saved in a database which also includes m3u and pls files. These files are parsed for the streaming url which works fine. (I only check if the streaming-url contains m3u or pls)

Now I just found out, that some of the links don't work in the MediaPlayer. For example: A station has following streaming link http://drumstep-aacp.rautemusik.fm If I open the link in my MediaPlayer it throws an Error (1,-2147483648) (usually unsupported file format).

If I open the same link in a browser, I'm redirected to the file http://drumstep-aacp.rautemusik.fm/listen.pls. (This is the reason for 2147483648 Error I guess)

Since I already wrote a PLS-Parser, this is not really a problem, but the PLS-File looks like

[playlist]
File1=http://drumstep-aacp.rautemusik.fm  //same link I entered at the beginning
Title1=#Musik.DrumStep
Length1=-1
NumberOfEntries=1
Version=2

If I would try opening the stream link again, this would start an endless loop. So how can I open that stream? (Another example is http://jam-aacp.rautemusik.fm)

The examples are shoutcast links, as far as I know...

Was it helpful?

Solution

The problem here comes down to the request headers. This server is using some crafty detection of browsers and non-browsers to help determine whether or not to redirect you to the real stream URL or not.

If you make a request for http://jam-aacp.rautemusik.fm/ with this header, you will get the .pls file:

Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8

Now, if you request the same URL without this header, you get a 302 redirect to the actual stream URL at http://80.237.157.12:12005/.

This server at 80.237.157.12:12005 is running SHOUTcast, which has its own detection. Instead of Accept header though, it uses User-Agent. If the user-agent string contains "Mozilla", then the server will send you the admin interface. Otherwise, it will send you the stream data.

In short, you need to make your requests without an Accept header, and with a User-Agent that does not contain Mozilla. By the way, you can easily figure this out yourself and reproduce the problem by downloading a copy of Fiddler.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top