我正在尝试从我的 android 应用程序(针对 5.0+)播放 .opus 媒体文件。此文件的来源是设备外部存储。
MediaPlayer 不断抛出 "java.io.IOException: Prepare failed.: status=0x1" 。请注意,我可以播放其他文件类型,如 mp3 和 aac
注意:已授予 READ_EXTERNAL_STORAGE 权限。
先感谢您。
下面是我位于 Android Fragment 中的部分代码:
public void playVoiceNote(VoiceNoteBO voiceNoteBO){
try{
Uri myUri = Uri.fromFile(new File(voiceNoteBO.getFileName())); //this resolves to the full path of the file.
MediaPlayer mediaPlayer = new MediaPlayer();
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
mediaPlayer.setDataSource(getActivity().getApplicationContext(), myUri);
mediaPlayer.prepare();
mediaPlayer.start();
}catch(Exception e){
//TODO
e.printStackTrace();
}
}
和堆栈跟踪:
06-04 18:31:46.129 1134-27920/? E/GenericSource: 从数据源初始化失败! 06-04 18:31:46.129 27425-27443/? E/MediaPlayer: 错误 (1, -2147483648) 06-04 18:31:46.129 27425-27425/? W/System.err: java.io.IOException: Prepare failed.: status=0x1 06-04 18:31:46.130 27425-27425/? W/System.err:在 android.media.MediaPlayer._prepare(本机方法) 06-04 18:31:46.130 27425-27425/? W/System.err:在 android.media.MediaPlayer.prepare(MediaPlayer.java:1135) 06-04 18:31:46.130 27425-27425/? W/System.err:在 com.frankyapps.privateread.prws.fragments.VoiceNotesFragment.playVoiceNote(VoiceNotesFragment.java:166) 06-04 18:31:46.130 27425-27425/? W/System.err:在 com.frankyapps.privateread.prws.fragments.VoiceNotesFragment$1.onClick(VoiceNotesFragment.java:76) 06-04 18:31:46.130 27425-27425/? W/System.err:在 com.frankyapps.privateread.prws.fragments.VoiceNotesFragment$RecyclerTouchListener.onInterceptTouchEvent(VoiceNotesFragment.java:217) 06-04 18:31:46.130 27425-27425/? W/System.err:在 android.support.v7.widget.RecyclerView.dispatchOnItemTouch(RecyclerView.java:2261) 06-04 18:31:46.130 27425-27425/? W/System.err:在 android.support.v7.widget.RecyclerView.onTouchEvent(RecyclerView.java:2389) 06-04 18:31:46.130 27425-27425/? W/System.err:在 android.view.View.dispatchTouchEvent(View.java:8471)