Your RadioButtons should be nested into RadioGroup and you should use setOnCheckedChangeListener on it. For the playing itself - if your .ogg-s are very small you should use SoundPool, otherwise MediaPlayer is needed, but you have to run the prepare() method in separate thread to prevent blocking the user input. Or you can use prepareAsync with setOnPreparedListener. Make sure you're doing a reset() on the MediaPlayer each time you switch to different .ogg file.
I'm not sure if they will fit in SoundPool, but most likely not. To make this sounds best you can create 3 MediaPlayers, setLooping and prepareAsync all of them in onCreate(). They should have OnPreparedListener set, and when all ready set the OnCheckedChangeListener of the RadioGroup (so if user switches the RadioButtons before players are ready nothing happens). The switching can be with pause() and start() so there will be no gap.
appforce wrote:That means the best way is to use a single player and when button is checked:
1. stop the player - catch IllegalStateException
2. setDataSource according to the checked button
4. setOnPreparedListener containing only mp.start()
Users browsing this forum: Google [Bot] and 4 guests