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 8194699
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T04:54:42+00:00 2026-06-07T04:54:42+00:00

I need to run many small sounds while the activity is running. Some files

  • 0

I need to run many small sounds while the activity is running.
Some files plays every fixed time interval (Ex. 5 seconds)
Some files will be played in a sequence when one finishes the next starts (ex. sound1, sound2, sound3) when the screen is touched.

Total sounds are around 35 short mp3 files (max 3 seconds).

What is the best way to implement this?

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-06-07T04:54:43+00:00Added an answer on June 7, 2026 at 4:54 am

    SoundPool is commonly used to play multiple short sounds. You could load up all your sounds in onCreate(), storing their positions in a HashMap.

    Creating SoundPool

    public static final int SOUND_1 = 1;
    public static final int SOUND_2 = 2;
    
    SoundPool mSoundPool;
    HashMap<Integer, Integer> mSoundMap;
    
    @Override
    public void onCreate(Bundle savedInstanceState){
      mSoundPool = new SoundPool(2, AudioManager.STREAM_MUSIC, 100);
      mSoundMap = new HashMap<Integer, Integer>();
    
      if(mSoundPool != null){
        mSoundMap.put(SOUND_1, mSoundPool.load(this, R.raw.sound1, 1));
        mSoundMap.put(SOUND_2, mSoundPool.load(this, R.raw.sound2, 1));
      }
    }
    

    Then when you need to play the sound, simple call playSound() with the constant value of your sound.

    /*
    *Call this function from code with the sound you want e.g. playSound(SOUND_1);
    */
    public void playSound(int sound) {
        AudioManager mgr = (AudioManager)mContext.getSystemService(Context.AUDIO_SERVICE);
        float streamVolumeCurrent = mgr.getStreamVolume(AudioManager.STREAM_MUSIC);
        float streamVolumeMax = mgr.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
        float volume = streamVolumeCurrent / streamVolumeMax;  
    
        if(mSoundPool != null){
            mSoundPool.play(mSoundMap.get(sound), volume, volume, 1, 0, 1.0f);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to run application in every X seconds, so, as far as cron
I need to run a standalone ruby script as Unix (linux) daemon. After running
I need to run some classic ASP locally before deployment to a legacy web
I need to run a task every 10 mins from morning 9 AM to
If I need to run many serial programs in parallel (because the problem is
I want to run many apps on the same emulator at the same time.
i need run code that will create a database and populate tables. i am
I need run ts:reindex when smth add in model or destroy from model. How
I need to run the application that I have made in Xcode on my
I need to run two ffmpeg commands, one after the other i.e., wait until

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.