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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T19:21:00+00:00 2026-06-14T19:21:00+00:00

Here’s what I am trying to achieve: When user presses Button A, a 30

  • 0

Here’s what I am trying to achieve: When user presses “Button A”, a 30 seconds “sound.mp3” starts playing over and over for 200 seconds and then stops. “Button B” plays the same sound for 400 seconds and stops.
Here’s my last attempt, using CountDownTimer (not sure if that’s the best approach or even possible):

public class MyClass extends Activity {

MediaPlayer player_test;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    this.requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.activity_rain);
    my_player();
}


public void my_player(){
        player_test = MediaPlayer.create(getApplicationContext(), R.raw.mysound);
        player_test.setLooping(true);
        player_test.start();
    }


public void onCompletion(MediaPlayer player_test) {
        player_test.stop(); 
            player_test.release(); 
        } 
});         



public void player_OnClick(View v) {

    switch (v.getId()) {
    case R.id.button_a:
          new CountDownTimer(200000, 1000) {       
                public void onTick(long millisUntilFinished) {
                    player_test.start();
                }       
               public void onFinish() {          
                   player_test.pause();
               }   
             }.start();
        break;
      case R.id.button_b:
          new CountDownTimer(400000, 1000) {       
            public void onTick(long millisUntilFinished) {
                player_test.start();       
            }       
           public void onFinish() {          
             player_test.pause(); }   
         }.start();
   break;
      }
}

Thank you for your answers.

  • 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-14T19:21:02+00:00Added an answer on June 14, 2026 at 7:21 pm

    It’s a good approach. However, you should fix some points in your code:

    • Don’t call player_test.start() in your my_player() method, it causes the player to start playing when your activity is created. You should only instantiate the player_test object in that method.
    • Don’t call player_test.start() in every tick of the CountDownTimer. You only need to call it one time to start playing.

    Call player_test.start() whenever any of the buttons A or B is clicked.

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

Sidebar

Related Questions

Here is what I am trying to achieve in PHP: I have this string:
Here is the code in a function I'm trying to revise. This example works
Here is the code: create table `team`.`User`( `UserID` bigint NOT NULL AUTO_INCREMENT , `Username`
Here is an example: I write html code inside of textarea, then I swap
Here's what I'm trying to accomplish with this program: a recursive method that checks
Here is the css: #content ul { font-size: 12px; } I am trying this:
Here is the problem that I am trying to solve. I have two folders
Here is the problem I'm trying to solve for my game. I have this
Here I am trying to change the value of the following check box while
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out

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.