How to know when the sound finished playing using soundPool - android

I am using sound pool to play a short sound files in android, but I want to play the sounds at for example, If I clicked a button to play a sound and clicked the button again, I don't want to play the sound as long as it is already playing . how ?

It looks like you should use a MediaPlayer Class instead of soundpool to accomplish this result, in combination with an OnClickListener.
A simple StackOverflow search returns the following:
MediaPlayer

Related

(Android) How to tell if a sound is playing in soundpool

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.

Playing music files in Android

I have a list of music files that should be played with my Android application. Actually user selects a list of files to be played for a specified time, and then clicks on 'start button'. Please tell me how I can implement it so that the following requirements are met:
The program should work, even if power button is pressed or the display is turned off.
Music files should be played one by one.
In order that the music continue after your application activities exit, you need to implement the playing itself as a Service (specifically, a started service). For playing the music, take a look at MediaPlayer. There is a discussion of using a MediaPlayer in a Service in the Media Player guide topic.
To play audio files, you can use Android's MediaPlayer class.
MediaPlayer mp = new MediaPlayer();
mp.setDataSource(audioFilePath);
mp.prepare();
mp.start();
This code snippet will load and play a single audio file. Take a look at the documentation for MediaPlayer to figure out how you might be able to leverage it for what you're trying to accomplish specifically.

How to play multiple ogg or mp3 at the same time..?

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

How to pause TextToSpeech along with the activity?

While developing TextToSpeech got a doubt that if we pause the activity how can we pause the TextToSpeeh along with the activity...If we resume the activity the text to speech will start where it has stopped previously...
How can we achieve this?
Thanks..
The TTS SDK doesn't have any pause functionality that I know of. But you could use synthesizeToFile() to create an audio file that contains the TTS output. Then, you would use a MediaPlayer object to play, pause, and stop playing the file. Depending on how long the text string is, it might take a little longer for audio to be produced because the synthesizeToFile() function would have to complete the entire file before you could play it, but this delay should be acceptable for most applications.

Android: I need a button that kills anything played by the MediaPlayer

I have an app that plays several different audio files on a loop, via several different buttons. I want to program a single button that will stop the MediaPlayer, regardless of what audio file is currently being played. Any help with this would be greatly appreciated.
Call stop() on your MediaPlayer object to stop the playback of whatever the MediaPlayer is playing.

Categories

Resources