How to play audio using Android NDK?

4,376 views
Skip to first unread message

Ngo Van Luyen

unread,
Sep 6, 2010, 10:02:25 AM9/6/10
to andro...@googlegroups.com
Hi all,

Do we have any chance to play audio in NDK C/C++ code (officially and unofficially, stable API/unstable API) ?

thanks,


--
Hello Android!
http://androidcore.com/

alan

unread,
Sep 6, 2010, 11:36:41 AM9/6/10
to android-ndk
you cant play audio from the ndk directly, you must call the java
AudioTrack api through JNI.

xianghui liu

unread,
Sep 6, 2010, 10:51:40 AM9/6/10
to andro...@googlegroups.com
I am looking for the method too?

do someone have ideas?

--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To post to this group, send email to andro...@googlegroups.com.
To unsubscribe from this group, send email to android-ndk...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/android-ndk?hl=en.

Mike v

unread,
Sep 7, 2010, 6:00:58 AM9/7/10
to android-ndk
-read this document http://android.wooyd.org/JNIExample/files/JNIExample.pdf,
especially section 4.2 (already mentioned in the newsgroup)
-then create a class that would play audio in java
-at startup register a java method to call to play a sound with your
JNI callback
-to play a sound from JNI (C/C++) call this method

also the paper mentiones that you should NOT cache the reference to
the class otherwise you get an exception (currently means the program
will crash)

you may also call from a (native) thread - then use
AttachCurrentThread() instead of GetEnv() to get JNI reference


greets
m

On 6 Sep., 16:51, xianghui liu <largep...@gmail.com> wrote:
> I am looking for the method too?
>
> do someone have ideas?
>
> On Mon, Sep 6, 2010 at 10:02 PM, Ngo Van Luyen <nvluye...@gmail.com> wrote:
>
> > Hi all,
>
> > Do we have any chance to play audio in NDK C/C++ code (officially and
> > unofficially, stable API/unstable API) ?
>
> > thanks,
>
> > --
> > Hello Android!
> >http://androidcore.com/
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "android-ndk" group.
> > To post to this group, send email to andro...@googlegroups.com.
> > To unsubscribe from this group, send email to
> > android-ndk...@googlegroups.com<android-ndk%2Bunsu...@googlegroups.com>
> > .

Ngo Van Luyen

unread,
Sep 7, 2010, 9:57:05 AM9/7/10
to andro...@googlegroups.com
I found this: http://groups.google.com/group/android-ndk/msg/f2b6f812ad0c00ee?pli=1

I'm trying to find a way to use libmedia from native code.



2010/9/7 Mike v <mike.va...@gmail.com>
To unsubscribe from this group, send email to android-ndk...@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/android-ndk?hl=en.

David Turner

unread,
Sep 9, 2010, 5:27:40 PM9/9/10
to andro...@googlegroups.com
Don't, your code *will* break in the future, or will simply not run on certain existing devices.
libmedia is not part of the exposed system libraries, and can be modified at will by OEMs or future platform releases.

alan

unread,
Sep 10, 2010, 4:12:40 AM9/10/10
to android-ndk
I found the performance of rendering audio from jni using audio track
was pretty good so I don't think you really need to use any private
apis

On Sep 9, 10:27 pm, David Turner <di...@android.com> wrote:
> Don't, your code *will* break in the future, or will simply not run on
> certain existing devices.
> libmedia is not part of the exposed system libraries, and can be modified at
> will by OEMs or future platform releases.
>
> On Tue, Sep 7, 2010 at 3:57 PM, Ngo Van Luyen <nvluye...@gmail.com> wrote:
>
> > I found this:
> >http://groups.google.com/group/android-ndk/msg/f2b6f812ad0c00ee?pli=1
>
> > <http://groups.google.com/group/android-ndk/msg/f2b6f812ad0c00ee?pli=1>I'm
> > trying to find a way to use libmedia from native code.
>
> > 2010/9/7 Mike v <mike.vasilj...@gmail.com>
> >> <android-ndk%2Bunsu...@googlegroups.com<android-ndk%252Buns...@googlegroups.com>

xianghui liu

unread,
Sep 11, 2010, 7:35:02 AM9/11/10
to andro...@googlegroups.com
I am porting a video player to android, and really donot know how
howto rendering audio from jni using audio track, as alan just says.

can you give me some reference, or example, thank you...

> android-ndk...@googlegroups.com.

mic _

unread,
Sep 11, 2010, 7:50:55 AM9/11/10
to andro...@googlegroups.com
At timed intervals, call your native audio mixing function and pass a
ShortBuffer or something similar to it that it can write the sample
data to. Then take the data from that buffer and write it to an
AudioTrack instance on the Java side.


/Michael

Reply all
Reply to author
Forward
0 new messages