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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T17:17:26+00:00 2026-06-13T17:17:26+00:00

I have 16 buttons in my application to play sounds when I click on

  • 0

I have 16 buttons in my application to play sounds when I click on them..I want to choose and import sounds from sd card. Any suggestions and examples on how to do that?

Here is my Java code :

public class App extends MultiTouchActivity {
SoundPool sp;
MediaPlayer mp;
int mSoundId, mSoundId1, mSoundId2, mSoundId3, mSoundId4, mSoundId5,
        mSoundId6, mSoundId7, mSoundId8, mSoundId9, mSoundId10, mSoundId11,
        mSoundId12, mSoundId13, mSoundId14, mSoundId15;
int mStreamId, mStreamId1, mStreamId2, mStreamId3, mStreamId4, mStreamId5,
        mStreamId6, mStreamId7, mStreamId8, mStreamId9, mStreamId10,
        mStreamId11, mStreamId12, mStreamId13, mStreamId14,
        mStreamId15 = 0;

@Override
public void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
    getWindow().clearFlags(
            WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    this.setVolumeControlStream(AudioManager.STREAM_MUSIC);
    sp = new SoundPool(5, AudioManager.STREAM_MUSIC, 0);
    mSoundId = sp.load(this, R.raw.dub1, 1);
    mSoundId1 = sp.load(this, R.raw.dub2, 1);
    mSoundId2 = sp.load(this, R.raw.dub3, 1);
    mSoundId3 = sp.load(this, R.raw.dub4, 1);
    mSoundId4 = sp.load(this, R.raw.dub5, 1);
    mSoundId5 = sp.load(this, R.raw.dub6, 1);
    mSoundId6 = sp.load(this, R.raw.dub7, 1);
    mSoundId7 = sp.load(this, R.raw.dub8, 1);
    mSoundId8 = sp.load(this, R.raw.dub9, 1);
    mSoundId9 = sp.load(this, R.raw.dub10, 1);
    mSoundId10 = sp.load(this, R.raw.dub11, 1);
    mSoundId11 = sp.load(this, R.raw.dub12, 1);
    mSoundId12 = sp.load(this, R.raw.dub13, 1);
    mSoundId13 = sp.load(this, R.raw.dub14, 1);
    mSoundId14 = sp.load(this, R.raw.dub15, 1);
    mSoundId15 = sp.load(this, R.raw.dub16, 1);
}

//

public void dubstep1(View view) {
    if (mStreamId != 0) {
        sp.stop(mStreamId);
    }
    mStreamId = sp.play(mSoundId, 1, 1, 1, 0, 1f);
}

public void dubstep2(View view) {
    if (mStreamId1 != 0) {
        sp.stop(mStreamId1);
    }
    mStreamId1 = sp.play(mSoundId1, 1, 1, 1, 0, 1f);
}

public void dubstep3(View view) {
    if (mStreamId2 != 0) {
        sp.stop(mStreamId2);
    }
    mStreamId2 = sp.play(mSoundId2, 1, 1, 1, 0, 1f);
}

public void dubstep4(View view) {
    if (mStreamId3 != 0) {
        sp.stop(mStreamId3);
    }
    mStreamId3 = sp.play(mSoundId3, 1, 1, 1, 0, 1f);
}

public void dubstep5(View view) {
    if (mStreamId4 != 0) {
        sp.stop(mStreamId4);
    }
    mStreamId4 = sp.play(mSoundId4, 1, 1, 1, 0, 1f);
}

public void dubstep6(View view) {
    if (mStreamId5 != 0) {
        sp.stop(mStreamId5);
    }
    mStreamId5 = sp.play(mSoundId5, 1, 1, 1, 0, 1f);
}

public void dubstep7(View view) {
    if (mStreamId6 != 0) {
        sp.stop(mStreamId6);
    }
    mStreamId6 = sp.play(mSoundId6, 1, 1, 1, 0, 1f);
}

public void dubstep8(View view) {
    if (mStreamId7 != 0) {
        sp.stop(mStreamId7);
    }
    mStreamId7 = sp.play(mSoundId7, 1, 1, 1, 0, 1f);
}

public void dubstep9(View view) {
    if (mStreamId8 != 0) {
        sp.stop(mStreamId8);
    }
    mStreamId8 = sp.play(mSoundId8, 1, 1, 1, 0, 1f);
}

public void dubstep10(View view) {
    if (mStreamId9 != 0) {
        sp.stop(mStreamId9);
    }
    mStreamId9 = sp.play(mSoundId9, 1, 1, 1, 0, 1f);
}

public void dubstep11(View view) {
    if (mStreamId10 != 0) {
        sp.stop(mStreamId10);
    }
    mStreamId10 = sp.play(mSoundId10, 1, 1, 1, 0, 1f);
}

public void dubstep12(View view) {
    if (mStreamId11 != 0) {
        sp.stop(mStreamId11);
    }
    mStreamId11 = sp.play(mSoundId11, 1, 1, 1, 0, 1f);
}

public void dubstep13(View view) {
    if (mStreamId12 != 0) {
        sp.stop(mStreamId12);
    }
    mStreamId12 = sp.play(mSoundId12, 1, 1, 1, 0, 1f);
}

public void dubstep14(View view) {
    if (mStreamId13 != 0) {
        sp.stop(mStreamId13);
    }
    mStreamId13 = sp.play(mSoundId13, 1, 1, 1, 0, 1f);
}

public void dubstep15(View view) {
    if (mStreamId14 != 0) {
        sp.stop(mStreamId14);
    }
    mStreamId14 = sp.play(mSoundId14, 1, 1, 1, 0, 1f);
}

public void dubstep16(View view) {
    if (mStreamId15 != 0) {
        sp.stop(mStreamId15);
    }
    mStreamId15 = sp.play(mSoundId15, 1, 1, 1, 0, 1f);
}
  • 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-13T17:17:27+00:00Added an answer on June 13, 2026 at 5:17 pm

    If you want to load from SD card, then get the path to the audio file that you want to play, and load it with SoundPool.load(String path, int priority). Environment.getExternalStorageDirectory will be useful for you here to help you find the files.

    Also as a side note, you should really learn some code reuse, your fingers will thank you. There’s no reason to have to duplicate the same behavior 16 times just to change one variable.

    You could replace all those 16 functions with:

    int[] mStreamIds = new int[16];
    int[] mSoundIds = new int[16];
    
    public void dubstep(int id) {
        if(mStreamIds[id] != 0){
           sp.stop(mStreamIds[id]);
        }
        mStreamIds[id] = sp.play(mSoundIds[id], 1,1,1,0,1f);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an application that should load sound from sd card and then play
I have a several buttons in my application and I want to apply a
In my application I have some link buttons there but when I right click
I want to play sound when button clicked, I have different the sounds,I list
I am using SimpleAudioEngine to play sounds in my cocos2D application. I have a
I have an application from where a play a radio stream using a service
In Application i have two buttons in which one button is used as a
I have quite a few buttons in my application, they vary in sizes based
Have two actionsheet buttons and one modalviewcontroller on mainviewcontroller in application. Now for two
A small - little question. I have seen many application having buttons like following.

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.