Reputation: 21
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?
Upvotes: 2
Views: 3278
Reputation: 678
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.
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
Upvotes: 3
Reputation: 6181
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();
Upvotes: 1
Reputation: 247
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
Upvotes: 1