Re: Android NDK mp3 support

957 views
Skip to first unread message

Pablo Hugo Reda

unread,
Apr 3, 2013, 7:18:12 AM4/3/13
to andro...@googlegroups.com
In my device this code can play a mp3


for call the player  
SNDplay(createAudioPlayer("pathandfile.mp3"));

I don't test with multiples files for now.

Glenn Kasten

unread,
Apr 3, 2013, 12:29:16 PM4/3/13
to andro...@googlegroups.com
I don't have that book; what was the new feature that it mentioned about MP3 playback?

The only way I know of to play MP3 via OpenSL ES in Android is the one shown
in the native-audio example code in NDK; see file jni/native-audio-jni.c.

But remember that example doesn't work with buffer queues.
If you want to use buffer queues, you should first decode the MP3 to PCM.

The standard way to decode with API 16 and higher is with the SDK MediaCodec; see

You can also decode without calling up from your native code via JNI,
by using the technique described in section "Decode audio to PCM"
of the NDK documentation opensles/index.html

Graham Wheeler

unread,
Apr 3, 2013, 4:13:03 PM4/3/13
to andro...@googlegroups.com
Yes, I have something similar for playing background audio, but for samples I am using buffer queue playback.


On Wednesday, April 3, 2013 4:18:12 AM UTC-7, Pablo Hugo Reda wrote:

Graham Wheeler

unread,
Apr 3, 2013, 4:15:58 PM4/3/13
to andro...@googlegroups.com
I went back and read what it said again: "Open SL ES has been updated in NDK R7 and now allows decoding compressed files such as mp3 files to PCM buffers." I guess that is what you are referring to at the end of your response. I'll take a look at that, thanks.

Glenn Kasten

unread,
Apr 3, 2013, 5:33:47 PM4/3/13
to andro...@googlegroups.com
That [decoding in OpenSL ES] should work, but in general I recommend using a JNI upcall to an SDK API if (a) the API is available, and (b) performance is acceptable with JNI and SDK.
As has been noted in this group :-) the SDK tends to get priority over NDK, and so I prefer NDK APIs only for performance-sensitive code or when the JNI would be too awkward / inappropriate.
Reply all
Reply to author
Forward
0 new messages