[英]Android MediaPlayer java.io.IOException: Prepare failed.: status=0x1, cant fix
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
其中大部分来自这里: 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.所以我尝试在 android 中使用 MediaPlayer 播放音乐,但准备总是失败并出现相同的异常。 Here is my onStartCommand function:
这是我的 onStartCommand 函数:
@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:和 onPrepared 函数:
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.
所以基本上我尝试调试,每次变量 e(这是例外)都是相同的
java.io.IOException: Prepare failed.: status=0x1.
Btw, the URL I pass is: http://www.ilemon.mobi/fightnIncastle1.mp3
, which should work fine.顺便说一句,我传递的 URL 是:
http://www.ilemon.mobi/fightnIncastle1.mp3
://www.ilemon.mobi/fightnIncastle1.mp3,应该可以正常工作。
TL;DR: My question, is why does it throw the expectation whenever I USE the mediaPlayer.prepare() method. TL;DR:我的问题是,为什么每当我使用 mediaPlayer.prepare() 方法时它都会引发期望。 I pass the URL using setDataSource.
我使用 setDataSource 传递 URL。 and prepare should call onPrepared when it is ready to play audio... but again, the exception happens, for some reason.
并且 prepare 应该在准备好播放音频时调用 onPrepared ...但是由于某种原因再次发生异常。 And I'm not sure why it happens.... that's what I'm asking.
而且我不确定为什么会这样……这就是我要问的。 (I have all the permissions in the manifest)
(我拥有清单中的所有权限)
Try using https://www.ilemon.mobi/fightnIncastle1.mp3 as the URL.尝试使用https://www.ilemon.mobi/fightnIncastle1.mp3作为 URL。 I suspect it's something to do with non-https stream.
我怀疑这与非 https 流有关。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.