I have created a soundboard and am having trouble getting just one sound to play at a time. If another button is pressed I want the current button to stop playing and the new button to begin. I also want sounds to stop when pressing the next or back button.
Is there any code that can help me out with this?
Here's some information for you that can help you solve your problem:
http://developer.android.com/reference/android/media/SoundPool.html
http://www.androidsnippets.com/playing-sound-fx-for-a-game
But like Falmarri pointed out, we're here to help on code and correct in need, not to write an app for you :)
The Android docs do not tell you how to build something, they only tell you what the parts do. Kinda like throwing parts at someone with detailed information of the parts, then expecting them to build an engine. The real world doesn't work that way!!
Here is what you need Paul. I use this code a lot:
private static SoundManager SM;//Field variable to hold sound manager.
SM = new SoundManager(); //Create sound manager
SM.initSounds(getBaseContext());
SM.addSound(1, R.raw.snd_loop_1);//Add sounds. Sounds go in /res/raw
SM.addSound(2, R.raw.snd_loop_2);
SM.addSound(3, R.raw.snd_ok_1);
Then you can call the sounds on demand with SM.playSound(1);
If you need a permanent running background loop, you can call the same sound with SM.playLoopedSound(2);
I hope it helps!
Related
How do I make my Text-To-Speech stop speaking? Right now, my TTS will start speaking when I launch my application, but I'm trying to make it stop speaking when a button on my Main Activity is pressed.
I have tried creating an onStop() method and using .stop, but to no avail.
May I please get some help on this issue?
You could do something along the lines of this ...
stopSpeakingButton.setOnClickListener(new
View.OnClickListener() {
String toSpeak = " ";
textToSpeech.speak(
toSpeaks,TextToSpeech.QUEUE_FLUSH,null);
});
As you gave us no code this a concept , not the most beautiful solution but will work if you adjust for your use case, the idea is to make it read string with onny a space in it!
I tried to place a file under /native/android/res/raw/bellbox.wav and add the build hint android.pushSound = bellbox but this does not work. At the moment it is not playing any sound also, I tried modifying the vibration pattern with the build hint android.pushVibratePattern = 1000 and did not have any luck either.
Please help me, thanks
Place the file under /native/android/raw/bellbox.wav
Hi I'm developing a game by using andengine.I have a player in my game created with TiledSprite.Also there box2d physic engine.Here is the porblem: Player is moving ahead.But a while later there is a wall on his top and if he wanna continue to go ahead, he has to incline.Incline method just make "player.setCurrentTileIndex(12);". So player image is getting small(incline position).Till here everything is right.But playerBody isn't getting small.That's why he still can't pass the wall by inclining.How can I solve it?
You can understand the problem with photos better:
In this picture, he can't go in there:
http://t1310.hizliresim.com/1g/j/tmpyd.png
In this picture, he can go in there but he can't:
http://j1310.hizliresim.com/1g/j/tmpz2.png
I searched this stutation and found this: destroy the fixture and create new one. But I need this solution with code examples. I couldn't get it well.
You have to create new body for it everytime.
By default the mediacontroller for video view appears only for 3 sec. I want it to be there untill the song is playing. I know I have to use this peice of code: -
mediacontrollername.show(0);
But apparently it doesn't seems to be doing its job correctly
What should I do for this?
Just in case anyone searched for this issue and still needs a solution, have a look at this: MediaController 3 Second Issue
I was using audiotrack to play some sounds in a loop. Now I need to know in which period of time I'm right now, so i decided to use setPositionNotificationPeriod which works quite good.
The problem is that it just work for the first "loop" but stop being called after that :\
The code looks like the following:
...
audioTrack.setPositionNotificationPeriod(bufferSize/numCalls);
audioTrack.setPlaybackPositionUpdateListener(this);
audioTrack.setLoopPoints(0,bufferSize,-1);
...
public void onPeriodicNotification(AudioTrack track)
{
Log.d("Hey I'm on call: "+numCall++);
}
With that I got just #numCalls# calls but I want them to be forever.
Any idea how to fix it?
Thank you very much
EDIT: I forgot to say I'm using an static audiotrack instead of stream