我希望我的应用程序播放 SD 卡中的 .ogg 音频文件,但媒体播放器和 SoundPool 无法对某些特定的 ogg 文件执行此操作。我无法播放的样本声音属于 Telegram。下面的代码适用于其他 ogg 文件和 mp3 格式,但在播放此类声音时会出错。
try {
mediaPlayer = new MediaPlayer();
mediaPlayer.setDataSource("/storage/emulated/0/Audio/test.ogg");
mediaPlayer.prepare();
mediaPlayer.start();
//works good for mp3 files
} catch (Exception e) {
e.printStackTrace();
Toast.makeText(context, "error", Toast.LENGTH_SHORT).show();
}
示例文件下载链接: http ://www.mediafire.com/download/fxr4z4hh7b2gv50/test.ogg
它抛出这个异常:
08-27 13:50:43.244: V/MediaPlayer[Native](5163): constructor
08-27 13:50:43.245: V/MediaPlayer[Native](5163): setListener
08-27 13:50:43.245: E/ExtMediaPlayer-JNI(5163): QCMediaPlayer could not be located....
08-27 13:50:43.245: E/MediaPlayer-JNI(5163): QCMediaPlayer mediaplayer NOT present
08-27 13:50:43.249: V/MediaPlayer[Native](5163): setDataSource(38, 0, 576460752303423487)
08-27 13:50:43.253: V/MediaPlayer[Native](5163): message received msg=8, ext1=0, ext2=0
08-27 13:50:43.253: V/MediaPlayer[Native](5163): notify(8, 0, 0) callback on disconnected mediaplayer
08-27 13:50:43.254: E/MediaPlayer[Native](5163): Unable to create media player
08-27 13:50:43.258: W/System.err(5163): java.io.IOException: setDataSourceFD failed.: status=0x80000000
08-27 13:50:43.258: W/System.err(5163): at android.media.MediaPlayer._setDataSource(Native Method)
08-27 13:50:43.258: W/System.err(5163): at android.media.MediaPlayer.setDataSource(MediaPlayer.java:1109)
08-27 13:50:43.259: W/System.err(5163): at android.media.MediaPlayer.setDataSource(MediaPlayer.java:1094)
08-27 13:50:43.259: W/System.err(5163): at android.media.MediaPlayer.setDataSource(MediaPlayer.java:1073)
08-27 13:50:43.259: W/System.err(5163): at android.media.MediaPlayer.setDataSource(MediaPlayer.java:1022)
08-27 13:50:43.259: W/System.err(5163): at com.bobardo.funnyringtones.MainActivity.onCreate(MainActivity.java:99)
08-27 13:50:43.259: W/System.err(5163): at android.app.Activity.performCreate(Activity.java:5977)
08-27 13:50:43.259: W/System.err(5163): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
08-27 13:50:43.259: W/System.err(5163): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2258)
08-27 13:50:43.259: W/System.err(5163): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2367)
08-27 13:50:43.259: W/System.err(5163): at android.app.ActivityThread.access$800(ActivityThread.java:148)
08-27 13:50:43.259: W/System.err(5163): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1283)
08-27 13:50:43.259: W/System.err(5163): at android.os.Handler.dispatchMessage(Handler.java:102)
08-27 13:50:43.259: W/System.err(5163): at android.os.Looper.loop(Looper.java:135)
08-27 13:50:43.259: W/System.err(5163): at android.app.ActivityThread.main(ActivityThread.java:5274)
08-27 13:50:43.259: W/System.err(5163): at java.lang.reflect.Method.invoke(Native Method)
08-27 13:50:43.259: W/System.err(5163): at java.lang.reflect.Method.invoke(Method.java:372)
08-27 13:50:43.259: W/System.err(5163): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:909)
08-27 13:50:43.259: W/System.err(5163): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:704)