Android: audio.* vs media.*, or can I combine them?

I’m doing an Android project. Following the documentation, I started off using audio.* for my sounds and music, but there’s an unacceptably high latency–it’s a puzzle game, and the sound for selecting a piece comes very noticeably later than the actual tap on screen. It feels way off.

So I switched to media.playEventSound, and although that took care of my latency problems, media.playSound handles background music very, very poorly. When I try to switch songs (these are mp3’s), the actual switch happens 5 to 10 seconds later! This is equally unacceptable.

Is it possible to use audio.* for streaming a background .mp3 while using media.* for low-latency event sounds? I got a crash when I tried it, but maybe I did something wrong. Or is there another solution people are using so that both sound effects and background music are responsive?

You probably will have issues trying to get this to work.  The audio library works at a higher level and handles mixing sounds, however the media.* library writes directly to the hardware and can’t mix.  You basically can have one thing write to audio and the mixing has to happen before it writes to the device. 

Rob

I managed to get media.* working better. Instead of just calling playSound when another playSound was already active (which resulted in 10-second switch times), I tried using stopSound first. But that just kept anything from playing. Finally, I used timer.performWithDelay to start the next song 50ms after the call to stopSound, and that works just as expected. Once I roll my own fade-out routine, I’ll be golden.

You probably will have issues trying to get this to work.  The audio library works at a higher level and handles mixing sounds, however the media.* library writes directly to the hardware and can’t mix.  You basically can have one thing write to audio and the mixing has to happen before it writes to the device. 

Rob

I managed to get media.* working better. Instead of just calling playSound when another playSound was already active (which resulted in 10-second switch times), I tried using stopSound first. But that just kept anything from playing. Finally, I used timer.performWithDelay to start the next song 50ms after the call to stopSound, and that works just as expected. Once I roll my own fade-out routine, I’ll be golden.