Reputation: 658
I want my app play .ogg audio files from SD card, but the media player and SoundPool can't do this for some specific ogg files. The sample sound that i have problem to play belongs to Telegram. The code below works well for other ogg files and mp3 formats but gives me error when playing this type of sounds.
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();
}
Download link of sample file: http://www.mediafire.com/download/fxr4z4hh7b2gv50/test.ogg
it throws this exception:
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)
Upvotes: 1
Views: 6346
Reputation: 2493
I've encountered a similar problem trying to play Telegram voice messages (see https://core.telegram.org/bots/api#getfile and https://core.telegram.org/bots/api#sendvoice). Not in android but in raspberry pi, although I'm guessing it could be for the same reasons.
It turns out that Telegram voice messages are OGG files encoded with OPUS. (maybe this is what user support_ms refers to in the latest comment to your question).
At least in ubuntu and raspbian, I didn't have the OPUS codec installed. I had to sudo apt-get install opus-tools
in order to get the opusdec
command line tool.
Using opusdec
I could decode the .ogg
file downloaded from Telegram to .wav
, and then play it with aplay
.
I really don't know the android equivalence to this but given your question is rather old I think this information could be of equal value to you and others trying to decode/play OPUS encoded files in *nix environments.
Hope it helps!
Upvotes: 3