Reputation: 3
I've tried a lot of things... but none seem to work. Most of them from here: Android MediaPlayer java.io.IOException: Prepare failed.: status=0x1
So I tried to play music using MediaPlayer in android, But the prepare always fails with the same exception. Here is my onStartCommand function:
@Override
public int onStartCommand(Intent intent,int flags, int startId)
{
Toast.makeText(this, "Service on start", Toast.LENGTH_LONG).show();
String lnk = intent.getExtras().getString("link");
mediaPlayerM.reset();
if(!mediaPlayerM.isPlaying())
{
try
{
mediaPlayerM.setDataSource(lnk);
mediaPlayerM.setAudioStreamType(AudioManager.STREAM_MUSIC);
mediaPlayerM.prepare();
}
catch (Exception e)
{
System.out.print(e.toString());
Toast.makeText(this, e.toString(), Toast.LENGTH_LONG).show();
}
}
return START_STICKY;
}
and the onPrepared function:
public void onPrepared(MediaPlayer mp)
{
if(!mediaPlayerM.isPlaying())
{
mediaPlayerM.start();
}
}
So basically I try debugging, and everytime variable e (which is the exception) is the same java.io.IOException: Prepare failed.: status=0x1.
Btw, the URL I pass is: http://www.ilemon.mobi/fightnIncastle1.mp3
, which should work fine.
TL;DR: My question, is why does it throw the expectation whenever I USE the mediaPlayer.prepare() method. I pass the URL using setDataSource. and prepare should call onPrepared when it is ready to play audio... but again, the exception happens, for some reason. And I'm not sure why it happens.... that's what I'm asking. (I have all the permissions in the manifest)
Upvotes: 0
Views: 273
Reputation: 515
Try using https://www.ilemon.mobi/fightnIncastle1.mp3 as the URL. I suspect it's something to do with non-https stream.
Upvotes: 0