Thursday, October 8, 2009

MediaPlayer vs SoundPool

Here is my recommendation if you are not sure which class to use - MediaPlayer or SoundPool when developing an Android application.

MediaPlayer:
If you were to play a background music in your application, you should go for MediaPlayer. MediaPlayer is my preferred class because it allows you to playback a lengthy audio file.

SoundPool:
As the name explains itself, SoundPool class allows you to playback a collection of short sound effects quickly and it does not lag much. Imagine yourself writing a game with several sound effects meant for different actions. You may use a HashMap to compile the list of SFXs and then play it by accessing the index number (key in the HashMap).

Summary:
Notice the adjectives I used for different classes.
Lengthy, theme = MediaPlayer
Short, effect = SoundPool

0 comments:

Post a Comment