Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7617529
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T03:10:22+00:00 2026-05-31T03:10:22+00:00

I am creating an application that will have multiple images on the screen, these

  • 0

I am creating an application that will have multiple images on the screen, these images will be buttons and when tapped will play a short sound. I researched this and could only find the current method I am using to play sounds, which does not seem responsive at all. I want that the sound plays quickly and is responsive to many rapid taps. I was unsure if this was even possible in Android.

The code I am using to play my sound is this:

    Button sound1;
MediaPlayer  firstSound;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    firstSound = MediaPlayer.create(SoundActivity.this, R.raw.click);


    sound1 = (Button) findViewById(R.id.Sound1);


    beaver.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {

            firstSound.start();

            }

    });



    }

My lag issue could also be perhaps down to the way I am using the media player object? I do feel that this should be smoother on my phone, any suggestions on how to play sounds in Android is appreciated.

Thanks.

Since discovering Sound Pool, I have edited my code to use this and it works perfectly, the new code looks like this:

SoundPool soundPool;
HashMap<Integer, Integer> soundPoolMap;
int soundID = 1;


Button sound1;
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);


    soundPool = new SoundPool(4, AudioManager.STREAM_MUSIC, 100);
    soundPoolMap = new HashMap<Integer, Integer>();
    soundPoolMap.put(soundID, soundPool.load(this, R.raw.click, 1));

    sound1 = (Button) findViewById(R.id.bBeaver);


    sound1.setOnClickListener(new View.OnClickListener() {

                public void onClick(View v) {

                    AudioManager audioManager = (AudioManager)getSystemService(Context.AUDIO_SERVICE);
              float curVolume = audioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
              float maxVolume = audioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
              float leftVolume = curVolume/maxVolume;
              float rightVolume = curVolume/maxVolume;
              int priority = 1;
              int no_loop = 0;
              float normal_playback_rate = 1f;
              soundPool.play(soundID, leftVolume, rightVolume, priority, no_loop, normal_playback_rate);

            }

    });


    }

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T03:10:24+00:00Added an answer on May 31, 2026 at 3:10 am

    You can use SoundPool. It fits what you want to do perfectly.

    You’ll just need a way to store the sound effect IDs corresponding to each image (or button).

    Perhaps extend Button to store associated sound effect ID. And use a common SoundPool to play the sound effect associated to the id when the button is touched.

    You can read more about SoundPool here.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am creating an application that will have a list of items that can
I'm creating a splash screen that will display while my Android application loads. I'd
I am creating a application that requires to store multiple attributes, and it will
I'm creating a web application that will use multiple types of users (e.g. Admin,
I am creating a java application that connects to multiple databases. A user will
I have an application that will support multiple sites. The site will be determined
I'm creating an application that will store a hierarchical collection of items in an
I'm creating an application that will store geolocation data for specific transactions. Should I
I am creating a small application that will be deployed on Window. The database
I'm currently creating an MVC application that will likely to expand to include a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.