Soundpool game with mp3 questions
I am making a game which will be using questions stored on a mp3, so for each question 开发者_开发知识库there will be a mp3 file.
The user will then press play to hear the mp3 and then add an answer for the mp3 in an edittext field. Which would then show correct or incorrect answer.
When the user clicks confirm answer the mp3 will move to the next question. So when the user presses play it will be question 2. Is it possible to do this and if so how would I go about implementing this. I would highly appreciate any advice on this.
Thanks.
It is recommended to use WAV or OGG format for sounds on Android, but in any case, you can play back your MP3s with the MediaPlayer class. For example:
MediaPlayer mp = MediaPlayer.create(YourActivityClass.this, R.raw.your_mp3_resource);
if(mp != null) {
mp.start();
}
Read the documentation regarding state and calling release() on finished MediaPlayer objects. Alternatively use one MediaPlayer object with the setDataSource() and prepare() methods.
Right now, you can use SoundPool or MediaPlayer
Both support mp3, but based on my experience, SoundPool will not always play Mp3 of more than 100kb. For those files you will have to use MediaPlayer.
One link comparing both.
精彩评论