Maybe anybody faced with this issue.
I use SoundPool for playing sounds in my app.
After playing the sound I need to do further action. But how can I determine that the sound has stoped?
All the sounds in the app have a different length, so I can not count the time. I need a different approach.
Thank you.
soundpool's purpose is to load and play simple small sounds without the need to monitor them.
what you probably need is MediaPlayer and setOnCompletionListener() :
http://developer.android.com/reference/android/media/MediaPlayer.html
http://developer.android.com/reference/android/media/MediaPlayer.html#setOnCompletionListener(android.media.MediaPlayer.OnCompletionListener)
Related
I'm building an app that plays multiple short sound effects in one activity.
There are over 80 buttons with each buttons that plays a specific sound effect.
I've searched about SoundPool and MediaPlayer and found out SoundPool is more efficient for short sound files.
Here's my question, if I should load over 80 sound effects in one activity, would SoundPool still be the better option? I ask because SoundPool loads the sound at once and reuses it, I think it's a bit heavy to load 80 sounds in one activity (Maybe I'm wrong.) Would like to hear the experts here for a better way or any advice!
Thanks in advance
It does not depend by the number of sounds, but from their size in terms of bytes. Every sound is loaded into memory and if they are too big, you could not have enough memory to load them all.
I would consider using AudioTrack. You instantiate it and when you have to play a sound you can read it from file system or assets or resources and add it to the play queue. It works only with PCM.
Is there a way I can tell if a certain sound is playing in SoundPool???
I.E.
if(MySound./*Command Goes Here*/()==true{
//Do stuff
}
I would appreciate if you could point me in the right direction or give me the code. I am not able to find any thing that does this on the docs.
This is not possible using SoundPool.
See Android SoundPool: get notified when end of played for two other ideas:
Use MediaPlayer, which provides an OnCompletionListener, instead of SoundPool
Use MediaPlayer in conjunction with SoundPool. Load the sound in a MediaPlayer beforehand to get the duration and keep track of whether the sound is done playing based its duration when played with SoundPool.
I am doing a cards game for android and I want that everytime a card is thrown, to play throwing sound. It is the same file. I will have also other sounds playing like background music , and certain clicks.
What do you recommend to use, sound pool or create MediaPlayback and play it? What would be the advantage/disdvantage to each one? should I use ogg or mp3/wave file?
Any help in this is appreciated.
Thank you
I would use the sound pool for short clips. I might be wrong but the sound pool has a smaller overhead plus it's the correct way to play short clips, it also allows you to specify how many times per second said sound clip can play which helps slower phones.
With regards to the mp3 vs ogg I use mp3. I don't believe there is any performance issues. Ogg is licence free but that doesn't really matter with regards to your app. Plus it might help if you plan on using these clips on another platform that doesn't play ogg files. No names mentioned :P
I'm trying to make a simple app that have various sounds and every sound (could be wav or mp3) have diferents volume controls but I donĀ“t know where start :S
I've been searching for the answer or similar answer but not exceed.
I will apreciate your help!
Initialize separate MediaPlayer objects. Use setVolume to control their volumes.
For more information:
http://developer.android.com/reference/android/media/MediaPlayer.html
I'm trying to play 20 ogg files at the same time using MediaPlayer.
This is because I want to make a mixing effect.
While one music is playing, other files also have to be played.
Actually, I already made an application with this function by iOS, and it didn't have any problems to play and mix.
And now, I should convert this app into android app.
so I sentenced 20 mediaplayer variables
MediaPlayer player1;
MediaPlayer player2;
MediaPlayer player3;
.....
play1 = (Button)findViewById(R.id.btn1);
play2 = (Button)findViewById(R.id.btn2);
play3 = (Button)findViewById(R.id.btn3);
......
play1.setOnClickListener(this);
play2.setOnClickListener(this);
play3.setOnClickListener(this);
......
and whenever I click each button, it play each sound and mix.
player1 = MediaPlayer.create(TestActivity.this, R.raw.md_cricket2);
player1.setLooping(true);
player1.start();
......
However, I have some problems at this point.
Two sounds mixing is ok, but when I tried to play more than 3 sounds,
some noises like "tick, tick" are added. It sounds like white noise..
I don't know why...
I thought it is really simple to make this mixing application in android, because
I already did it in iOS, but I don't know what the problem is...
Is there anybody who can advise me?
I think soundpool is not an answer. It is only for short sounds.
MediaPlayer is not proper to play multiple sounds at the same time?
Then, How can I make this function?
Playing sounds simultaneously with multiple media players is not recommend (crashes may occur).
You'd better use soundpool. Unfortunately, I don't have any experience with it myself so I can't help you there, but perhaps this post will help