0

So I've created a simple soundboard app in Android Studio and run it using ADB to test it on my phone. It works perfectly fine but my issue is when I tap on a button to play a sound clip there is a second delay before I can press it again and here the sound. I would like to be able to press the button as quickly as I want and have it play the sound with as little as delay as possible.

Another issue I have with the button is that I'd like for it to stop playing one sound when if I press another button.

All I'm using right now is the Mediaplayer class and setOnClickListener. It's very simple not many lines of code. I feel like I've attempted to look into this in the documentation but I'm not sure if my questions are worded correctly so any suggestions on more detailed questions I could search online myself would be appreciated.

I'm not sure if this is a problem caused by ADB or using my device that creates this lag so any personal experience would be greatly appreciated as well.

******EDIT****** For those asking for code.

    //set up the button sound
    MediaPlayer mpButtonClick = MediaPlayer.create(this, R.raw.sound);
    Button button = (Button) findViewById(R.id.button);
    //button 1
    button.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            mpButtonClick.start();
        }
    });

I've got 5 buttons and they all work like this. I just play sounds from a resource folder and 4 of the clips are less than 2 seconds long.

Since I'm new to this I'm unaware of asynctask and SoundPool I'll look into those right now.

********EDIT 2**********

So after doing some research I've decided SoundPool will most likely be what best suited for what I need. But I've seen that it creates issues for others who develop with it here and on the Web in general. I also am not using ogg files which people say are more likely to work with SoundPool across different devices.

asynctask sounds like it could get the job done but I don't believe that it's intended to use in that way.

I also download six apps from the app store that I felt I would like mine to resemble and the one that was the best wasn't developed in an android environment but with the Unity engine. And since I have a little experience with that as well I believe I'll go that route thank you all.

Community
  • 1
  • 1

1 Answers1

0

Use SoundPool instead... you can pre-load the sounds and it'll let you have overlapping sounds.

More information here.

Community
  • 1
  • 1
Buddy
  • 10,874
  • 5
  • 41
  • 58