【发布时间】:2015-02-26 19:40:46
【问题描述】:
我调试了一下,看到path = /storage/emulated/0/Music/test_cbr.mp3
经过测试
mp.setDataSource(path);
和
mp.setDataSource(getApplicationContext(),Uri.parse(path));
但是两种方式都会在 setDataSource 处给出非法状态异常,为什么?
try
{
MediaPlayer mp = new MediaPlayer();
// Uri fileUri = ContentUris.withAppendedId(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, 1834);
// mp.setDataSource(context, fileUri);
mp.setAudioStreamType(AudioManager.STREAM_MUSIC);
mp.release();
mp.reset();
mp.setDataSource(getApplicationContext(),Uri.parse(path));
// mp.reset();
// mp.setDataSource(context, uri);
mp.prepare();
mp.start();
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (SecurityException e) {
e.printStackTrace();
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
编辑和回答
现在一切正常。我将 mp 拼错为 mediaplayer。现在我纠正它。感谢朋友们的帮助。
【问题讨论】:
-
你能发布你的错误堆栈跟踪吗?
标签: android android-mediaplayer illegalstateexception