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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T22:47:44+00:00 2026-06-13T22:47:44+00:00

I have button that plays sound using soundpool. I want to open my application

  • 0

I have button that plays sound using soundpool. I want to open my application and then manually load .mp3 file from SD card and play it with my button.
My java code :

package com.example.idea;

    import android.media.SoundPool;
    import android.os.Bundle;
    import android.app.Activity;
    import android.view.Menu;
    import android.view.View;

    public class MainActivity extends Activity {
    SoundPool sp;
    int mSoundId;
    int mStreamId;
    @Override
    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    mSoundId = sp.load(this, R.raw.sound1, 1);

}

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.activity_main, menu);
    return true;
}

    public void button1(View view){
    if (mStreamId != 0) {
    sp.stop(mStreamId);
}
    `mStreamId = sp.play(mSoundId, 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-13T22:47:45+00:00Added an answer on June 13, 2026 at 10:47 pm

    Since your SD card is usually (but necessarily) your external storage, I’ll present such a solution below. (If your external storage points to an internal card in your device — e.g. on a tablet –, my code will return a path to that folder.)

    Therefore, you should use another version of the load method of SoundPool, which expects a file path (as a String) instead of a resource ID. This is the official link to the method’s documentation. To get the path of the file, you can use this method:

    private String getFullFilePath(Context context, String filename) {  
        File directory = context.getExternalFilesDir(null);
        File file = new File(directory, filename);
        if (!file.canRead()) {
            // error handling
        }
        return file.getAbsolutePath();  
    }
    

    In this case, your relevant code snippet would look like this:

    String path = getFullFilePath(getApplicationContext(), "sound1.wav");
    mSoundId = sp.load(path, 1);
    

    To sum up, the above code will search for the file in your application’s external storage directory. This is the standard way of accessing a non-internal storage file (i.e. it’s device dependent if the external storage is your SD card or something else).


    UPDATE:

    Of course, before using the external storage, you should check whether the media is readable (and in case of writing requirements, writable). You can find more information on this official page.

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

Sidebar

Related Questions

In my application, I have put a button that plays its own sound by
I have an audio file that plays using avaudioplayer, I want to able to
I have a button that plays a sound and i want to prevent users
I have a simple button that plays a small MP3 file, looping it 30
I have a button in a NIB file that plays a sound and calls
i have a button that plays a sound. When i push the button multiple
I have a button that plays an audio file on its click listener. If
I have a website that plays sound when you click a button. This is
I have an android app with a button that plays a sound. the code
I have a button that I want to make disappear if anything is tapped

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.