Media Player 在 Lollipop 设备中不工作
Media Player is not working in Lollipop device
我正在尝试通过媒体播放器播放音频文件。它在 Marshmallow devices.Unfortunately 中工作,在 Lollipop 设备中不工作。它显示 IOException java.io.IOException: Prepare failed.: status=0x105
。我不明白会出现什么问题。我知道这是常见问题。但是我没有从旧问题中得到任何解决方案。
try {
mPlayer.setDataSource(mChapter.getChapterAudioLink());
} catch (IllegalArgumentException e) {
e.printStackTrace();
Toast.makeText(context, "You might not set the URI correctly!", Toast.LENGTH_LONG).show();
} catch (SecurityException e) {
e.printStackTrace();
Toast.makeText(context, "You might not set the URI correctly!", Toast.LENGTH_LONG).show();
} catch (IllegalStateException e) {
e.printStackTrace();
Toast.makeText(context, "You might not set the URI correctly!", Toast.LENGTH_LONG).show();
} catch (IOException e) {
e.printStackTrace();
}
try {
mPlayer.prepare();
mPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mediaPlayer) {
playOrPause.setImageResource(android.R.drawable.ic_media_pause);
mAudioDialog.show();
mPlayer.start();
mDurationTextView.setText(convertSecondsToHMmSs(mPlayer.getDuration()) + "");
mSeekbarAudio.setMax(mPlayer.getDuration());
}
});
// mPlayer.prepareAsync();
} catch (IllegalStateException e) {
e.printStackTrace();
Toast.makeText(context, "You might not set the URI correctlyyy!", Toast.LENGTH_LONG).show();
} catch (IOException e) {
e.printStackTrace();
Toast.makeText(context, "You might not set the URI correctlyy!", Toast.LENGTH_LONG).show();
}
我收到最后一个 IOException。
URL 中的空格对我造成了这个问题。我用 %20
替换了空格,它工作正常。
mPlayer.setDataSource(mChapter.getChapterAudioLink().replaceAll(" ","%20"));
我正在尝试通过媒体播放器播放音频文件。它在 Marshmallow devices.Unfortunately 中工作,在 Lollipop 设备中不工作。它显示 IOException java.io.IOException: Prepare failed.: status=0x105
。我不明白会出现什么问题。我知道这是常见问题。但是我没有从旧问题中得到任何解决方案。
try {
mPlayer.setDataSource(mChapter.getChapterAudioLink());
} catch (IllegalArgumentException e) {
e.printStackTrace();
Toast.makeText(context, "You might not set the URI correctly!", Toast.LENGTH_LONG).show();
} catch (SecurityException e) {
e.printStackTrace();
Toast.makeText(context, "You might not set the URI correctly!", Toast.LENGTH_LONG).show();
} catch (IllegalStateException e) {
e.printStackTrace();
Toast.makeText(context, "You might not set the URI correctly!", Toast.LENGTH_LONG).show();
} catch (IOException e) {
e.printStackTrace();
}
try {
mPlayer.prepare();
mPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mediaPlayer) {
playOrPause.setImageResource(android.R.drawable.ic_media_pause);
mAudioDialog.show();
mPlayer.start();
mDurationTextView.setText(convertSecondsToHMmSs(mPlayer.getDuration()) + "");
mSeekbarAudio.setMax(mPlayer.getDuration());
}
});
// mPlayer.prepareAsync();
} catch (IllegalStateException e) {
e.printStackTrace();
Toast.makeText(context, "You might not set the URI correctlyyy!", Toast.LENGTH_LONG).show();
} catch (IOException e) {
e.printStackTrace();
Toast.makeText(context, "You might not set the URI correctlyy!", Toast.LENGTH_LONG).show();
}
我收到最后一个 IOException。
URL 中的空格对我造成了这个问题。我用 %20
替换了空格,它工作正常。
mPlayer.setDataSource(mChapter.getChapterAudioLink().replaceAll(" ","%20"));