Code Painters The Art of Coding


Android MediaPlayer and short WAV files

I've recently observed an interesting issue with MediaPlayer on HTC Desire and Legend (I had no chance yet to check other phones) - it refuses to play a short, otherwise perfectly valid 22050Hz linear PCM 16-bit WAV file. Strictly speaking, there's no error reported or any exception visible in logs, but also there is no sound played.

The only exceptional thing about the WAV files we used is the length, the files are about 80ms each - short beeps to play as a button press feedback. To solve the problem it was necessary to append a period of silence to each file, to make it at least 200ms long.

I can guess the reason - perhaps the media player implementation disables the decoder right after injecting the last chunk of data, not waiting for this very last chunk to decode?