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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T10:31:57+00:00 2026-05-16T10:31:57+00:00

My question is a very simple one i’m sure. It’s just I’m not quite

  • 0

My question is a very simple one i’m sure. It’s just I’m not quite sure how to effectively describe what i’m trying to achieve.

Anyway to the point, I have a simple button, I know how to “link” a raw sound file to hand make it play. BUT what i want to do is maybe link a 3 second sound to the button and just have it loop while the user holds the button, and then stops playing when the button is let go. Anyone have any example links they could share that would be great! Thank you!

edit:
Thank you Cpt.Ohlund!

Thanks that was definately helpful and did the trick, however i ran into 1 more small problem maybe you could help me with I’m using a “Custom Button” as seen on http://developer.android.com/resources/tutorials/views/hello-formstuff.html

It worked fine before i added the “onTouch Listener. The Button now doesn’t use it’s android:state_pressed Item it just displays the normal item but not the pressed item. At least It plays the sound now. But, Any Ideas?

  • 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-16T10:31:58+00:00Added an answer on May 16, 2026 at 10:31 am

    You could use the following, just change R.raw.hit to your own soundfile:

    public class XButtonSound extends Activity implements OnTouchListener {
    
    private int sound;
    private SoundPool sounds;
    
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    
        Button donePlacing = new Button(this.getApplicationContext());
        donePlacing.setId(1);
        donePlacing.setText("Play");
        donePlacing.setOnTouchListener(this);
    
        this.addContentView(donePlacing, new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));
    
    
        sounds = new SoundPool(5, AudioManager.STREAM_MUSIC, 0);
        sound = sounds.load(this.getApplicationContext(), R.raw.hit, 1);
    }
    
    
    @Override
    public boolean onTouch(View arg0, MotionEvent event) {
    
        switch (event.getAction() ) { 
        case MotionEvent.ACTION_DOWN: 
            System.out.println("touch");
            sounds.play(sound, 1, 1, 1, -1, 1);
            break;
        case MotionEvent.ACTION_UP:
            System.out.println("up");
            sounds.autoPause();
            break; 
        }
    
        return true;
    }
    

    }

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

Sidebar

Related Questions

Hopefully a question with a very simple answer, but it's not one that I've
I have very simple question but the answer is still not clear. If i
This is my first question here, probably a very simple one but I can't
Here is one very simple question(or at least at first sight).Let's say we have
I have a very simple question that is not answered on WordPress Codex. The
The question is a very simple one, can you have more than one index
My question is very simple and can be understood in one line: Is there
I am sure my question is very simple for some, but I cannot figure
This is a very simple question, but one I can't find an answer to.
I'm sure this is a very simple question but please take a look at

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.