tags:

views:

112

answers:

1

I'm looking for some way in Android to play in-memory audio in a manner analogous to the waveOutOpen family of methods in Windows programming.

The waveOut... methods essentially let an application create arrays of sample values (like in-memory WAV files without the headers) and dump them into a queue for sequential playback. Windows transitions seamlessly from one array to the next, so as long as the application keeps dumping arrays into the queue ahead of playback, the program can create and play continuous audio of any arbitrary length. The Windows API also incorporates a callback mechanism that the application can use to indicate progress and load additional buffers.

As far as I can tell, the Android audio API lets an application play a file from local storage or a URL, or from a memory stream. Is there any way to get Android to "queue up" MediaPlayer.start() calls so that one player transitions (without glitches) into the next upon play completion? It appears that Jet does something like this, but only with its own internal synthesis engine.

Is there any other way of accessing Android audio in a waveOutOpen way?

+3  A: 
android.media.AudioTrack

... is the class you are probably looking for.

http://developer.android.com/reference/android/media/AudioTrack.html#AudioTrack%28int,%20int,%20int,%20int,%20int,%20int%29

After creating it you simply feed it with binary data with given format using following method:

AudioTrack.writeTo(...)
radek-k
Thanks, that looks like exactly what I was looking for. Do you know if this works in the emulator? In Windows Mobile, the waveOutWrite methods only kind of worked in the emulator (lots of pauses and stuttering) while working fine in the real devices.
MusiGenesis
I didn't try it personally but I came across it when I was looking for a way to play a MP3 content from a stream. Using MediaPlayer in emulator works fine unless you have debbuger connected. It may be similar with AudioTrack.
radek-k
I'm quite sure both the MediaPlayer and SoundPool (know this one for a fact, was looking at it earlier today) use AudioTrack internally, so I'd say it'll definitely run (esp. seeing how it can manage to run my native code as well).
Grant Peters