How to play mp3 files using sonic ndk in Android?

advertisements

I am using Sonic Ndk in my app to play audio from this sample https://github.com/waywardgeek/sonic-ndk. but it can't play mp3 files.


Android NDK has no such apis. but there are several solutions for play mp3 in ndk.

  1. You can use MediaPlayer platform api. See https://android.googlesource.com/platform/frameworks/av/+/master/include/media/mediaplayer.h

    But, it is not public api and it can be broken by manufacturer.

  2. You can use OpenMAX AL interface. Recently, ndk support OpenMAX AL.

    But, it is very difficult to use, and few references. :(

    And only support api level 14 or above.

  3. You can call java method in jni.

    You can see how call java method in c/c++ source in below source. https://android.googlesource.com/platform/frameworks/base/+/master/media/jni/android_media_MediaScanner.cpp

    I think this is better solution than others.