Reputation: 161
I have some problem with playing audio from url, namely I get two following exceptions:
E/MediaPlayer(3387): error (1, -2147483648)
E/MediaPlayer(3387): Error (1,-2147483648)
In my code, I declare a MediaPlayer object and String with URL
MediaPlayer mMediaPlayer;
String url ="http://ciacho090.wrzuta.pl/audio/31h2JLMRCE7/eminem_soldier.mp3";
In my MainActivity, I initialize mMediaPlayer by default constructor and set stream type
mMediaPlayer = new MediaPlayer();
mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
Then I set source on url and request async prepare catching possibility exceptions by this code:
try
{
mMediaPlayer.setDataSource(url);
mMediaPlayer.prepareAsync();
}
catch(IOException e)
{
e.printStackTrace();
}
catch (IllegalArgumentException e)
{
e.printStackTrace();
}
catch (IllegalStateException e)
{
e.printStackTrace();
}
finally I set onPreparedListener:
mMediaPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener()
{
@Override
public void onPrepared(MediaPlayer mp)
{
mp.start();
}
});
I get above exceptions and the music doesn't play. In Manifest, I have declared these permissions and min sdk version to 8
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WAKE_LOCK" /> //i know- it's unneccesary
Maybe settings in manifest are cause of issues or url link to music file. I don't know whether it's capable to progressive download. Maybe can You give me some link? And why it doesn't work?
Upvotes: 2
Views: 7373
Reputation: 23269
Your URL is returning html. MediaPlayer
doesn't know anything about playing HTML pages. Just because it ends in .mp3
doesn't mean it is an mp3.
You can check this easily by just visiting this page in a browser:
http://ciacho090.wrzuta.pl/audio/31h2JLMRCE7/eminem_soldier.mp3
Here's a "real" mp3 you can test with:
http://ia700200.us.archive.org/1/items/testmp3testfile/mpthreetest.mp3
In short: make sure you are passing a url that returns an mp3 or other supported audio format.
Upvotes: 4