I started developing a simple sound playing app:
You got up to 16 buttons on the screen and you can assign to every
button a sound file from your sdcard. Everytime you hit a button the
assigned sound is played. Hitting the button again while the sound is
played, the sound starts all over.
I got it roughly working but am stuck for weeks now with playing the
sounds the way I need them. This are my requirements:
- The sounds should start instantly with a very short delay
- The user should be able to select any sound file (even though it
would be OK if my app would need to do a conversion of the file to
make it work)
- Multiple sound can be played at the same time (eg. clicking button 1
and while the sound from that button plays, hitting button 2 starts
the second sound without stoping the first one)

I thought this would be a nice simple app to start learning the
plattform, but man was I wrong. ;-)

By now I used the SoundPool and the MediaPlayer:
The MediaPlayer is good because it allows to play every (even long)
sound files. The big problem with this approach is the latency it has
to play the file after the button is clicked. It takes up to half a
second to play the file (both on the emulator and on my HTC Desire).
This is way to long to play nice effects by hitting the button fast
multiple times. Also I read that you shouldn't use more than 2-3
MediaPlayer objects, I didn't have any problems by now with my up to
16 MediaPlayer objects, not on the emulator nor on the device, but I
guess there must be a reason why this is mentioned in the
documentation.
On loading I "setDataSource" for the MediaPlayers and "prepare" them.
I a button is clicked I use this:
if (mMediaPlayer.isPlaying())
{
        mMediaPlayer.seekTo(0);
}
else
{
        mMediaPlayer.start();
}


The SoundPool has big big problems if longer sounds are selected.
Short sound files are OK, they are played nicely with a very short
delay. But if the user selects bigger sound files I get out of memory/
heap errors and the sounds are not played, sometimes the application
even crashs. This errors can't even be catched because SoundPools
function don't throw any exceptions, it just don't play or crashs.
If a button is clicked, the sound is played with this code:
if (mPlayingSoundID > 0)
{
        mSoundPool.stop(mPlayingSoundID);
}
mPlayingSoundID = mSoundPool.play(mSoundID, mVolume, mVolume, 1, -1,
1f);


So does anybody know if I could accomplish my requirements above on an
android system? It just look like I can't. Could AudioTrack help? But
how would I do that? Couldn't find any samples or tutorials.
Do perhaps something with MIDI help here? Could I load the samples as
MIDI samples and play them instantly like I needed (sorry if this is
nonsense - I'm not a pro with this audio stuff)?

Hope for some help here because I'm stuck for weeks now with this
problem(s).
Thanks

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to