I find Android SoundPool can only play 6 seconds mp3, How can I break this limits? And are there any other mp3 player except MediaPlay?
3 Answers
You can keep using soundpool for longer sounds too. You can play nearly around 30 seconds. But you might need to modify your files. You should convert your sound file to ogg, it always gave me better results when using soundpool.
- Change your sound file's sampling rate to 16000 Hz
- Change your audio channel to mono, instead of stereo.
- Make sure your file after these processes is smaller than 1 mb in size.
Now, I use an online converter to do that. You can do all those steps through the online converter. Here is a link that i use: http://audio.online-convert.com/convert-to-ogg

- 650
- 1
- 7
- 16
-
Have you noticed shorter playback lengths for files of higher frequency? I've got a few note files, all recorded as 24 bit 22 kHz, and the higher pitched notes only play for 5.5 seconds but the lower pitched notes play for 12. – Cody Sep 04 '17 at 15:35
-
I did not notice, but it is very interesting finding. I will check some time :) – Orcun Sep 04 '17 at 19:20
-
fantastic solution!! thank you so much! – Tao Dec 03 '21 at 13:55
See, first of all, soundpool is used for small size audio only and time is not a constraint. So it's totally wrong to think that it can play only 6-second audio, The limit is of file size it can buffer and it's maximum 1 Megabyte.
So you can use a maximum size of 1M.
How can I break this limits?
You can use MediaPlayer class provided by android, see the documentation.
If you want step by step tutorial, here is a one.
Here you can read more about it.
Here is an example of how to play audio that's available as a local raw resource (saved in your application's res/raw/ directory):
MediaPlayer mediaPlayer = MediaPlayer.create(context, R.raw.sound_file_1);
mediaPlayer.start(); // no need to call prepare(); create() does that for you
And here is how you might play from a URI available locally in the system (that you obtained through a Content Resolver, for instance):
Uri myUri = ....; // initialize Uri here
MediaPlayer mediaPlayer = new MediaPlayer();
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
mediaPlayer.setDataSource(getApplicationContext(), myUri);
mediaPlayer.prepare();
mediaPlayer.start();
-
but I want to play different sounds simaltaneously. It seems the MediaPlayer can n't solve it; Can I build a buffer manager for the SoundPool... – Rigar Su Mar 29 '17 at 01:48
-
In soundpool you can do it when you initialize the constructor, you can pass as many numbers as you wanna play, See this answer: http://stackoverflow.com/questions/5957444/playing-sounds-simultaneously-android – TapanHP Mar 29 '17 at 04:46
-
What would you suggest to game background music ? a `<1mb` file with `soundpool` or `mediaplayer` ? – Royi Namir Apr 28 '18 at 10:25
-
@TapanHP OK - so what if I want background music PLUS short explosion sounds when click ? should I mix them both ? – Royi Namir Apr 28 '18 at 10:38
-
Well, I haven't done any implementation exactly as you are saying but it really depends on your use case, but I am not the person has so much experienced with that, so better you ask a separate question or read docs and do implement it – TapanHP Apr 28 '18 at 10:40
-
check out this one he has done same thing, ask him https://stackoverflow.com/a/21585227/5476209 – TapanHP Apr 28 '18 at 10:43
Instead Of Soundpool , Use Media Player Class
First Create The Media Player Object
MediaPlayer mediaPlayer;
After That Initialize it - Create A Raw Folder Inside The Res folder of Your Project and Put MP3 File Into This Raw Folder and Initialize it .
mediaPlayer = MediaPlayer.create(this, R.raw.song);
After That Use These Two Methods For Play and Pause
mediaPlayer.play();
// For Play Music
mediaPlayer.Pause();
// For Pause The Music
For More Knowledge About Media Player
Use Thsese Tutorial
https://www.tutorialspoint.com/android/android_mediaplayer.htm
And If ou Want To Play Music With URL Then Use This Tutorial

- 247
- 4
- 14