MediaPlayer error when playing MP3 stream
I'm playing around with code for playing an MP3 stream, the code is as follows;
try
{
URL url = new URL("streamURL")开发者_开发百科;
URLConnection con = url.openConnection();
con.connect();
con.getContent();
MediaPlayer mp = new MediaPlayer();
mp.setDataSource(con.getURL().toString());
mp.prepare();
mp.start();
}
catch(Exception e)
{
}
Crude, but I'm only playing around at the minute. This code works fine in the emulator, but when running on my Galaxy S I find the error "Command PLAYER_INIT completed with an error or info -105", in the log file.
Has anyone come across this before, and is this something specific to the Galaxy ?
Many thanks in advance,
Neil.
I guess that you are trying to play an .pls directly or something similar.
try this out:
1: the code
mediaPlayer = MediaPlayer.create(this, Uri.parse("http://vprbbc.streamguys.net:80/vprbbc24.mp3"));
mediaPlayer.start();
2: the .pls file
This URL is from BBC just as an example. It was an .pls file that on linux i downloaded with
wget http://foo.bar/file.pls
and then i opened with vim (use your favorite editor ;) and i've seen the real URLs inside this file. Unfortunately not all of the .pls are plain text like that.
tested with android 1.6 and 2.2.
Try the following instead, and see if this works (untested):
try {
URL url = new URL("streamURL");
URLConnection con = url.openConnection();
con.connect();
con.getContent();
MediaPlayer mp = MediaPlayer.create(this, Uri.parse(con.getURL.toString()));
mp.start();
} catch(Exception e) { }
精彩评论