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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T21:28:24+00:00 2026-05-18T21:28:24+00:00

i have this two button.as i press the first it plays an mp3 file.but

  • 0

i have this two button.as i press the first it plays an mp3 file.but if i press the second and the first mp3 hasnt finished yet,they play both together.how could i fix it??this is my btn code!!thanks

Button button = (Button) findViewById(R.id.btn);  
        button.setOnClickListener(new View.OnClickListener() {  
           public void onClick(View v){

            MediaPlayer mp = MediaPlayer.create(this, R.raw.myalo);  
            mp.start(); 
            Toast.makeText(this, "Eisai sto myalo", Toast.LENGTH_SHORT).show();

           }     

        });       

        Button button2 = (Button) findViewById(R.id.btn2);  
        button2.setOnClickListener(new View.OnClickListener() {  
           public void onClick(View v){

            MediaPlayer mp = MediaPlayer.create(this, R.raw.thryleole);  
            mp.start(); 
            Toast.makeText(this, "thryle ole trelenomai", Toast.LENGTH_SHORT).show();
           }
  • 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-18T21:28:25+00:00Added an answer on May 18, 2026 at 9:28 pm

    You can achieve this easily by checking to see if the MediaPlayer is playing before you start it. You’d want to do something like this:

    Button button = (Button) findViewById(R.id.btn);  
    button.setOnClickListener(new View.OnClickListener() {  
       public void onClick(View v){
           if (mp.isPlaying() == false){
               MediaPlayer mp = MediaPlayer.create(olympiakos.this, R.raw.myalo);  
               mp.start(); 
               Toast.makeText(olympiakos.this, "Eisai sto myalo", Toast.LENGTH_SHORT).show();
           }
       }     
    
    });       
    
    Button button2 = (Button) findViewById(R.id.btn2);  
    button2.setOnClickListener(new View.OnClickListener() {  
       public void onClick(View v){
           if (mp.isPlaying() == false){
               MediaPlayer mp = MediaPlayer.create(olympiakos.this, R.raw.thryleole);  
               mp.start(); 
               Toast.makeText(olympiakos.this, "thryle ole trelenomai", Toast.LENGTH_SHORT).show();
           }
       }
    });
    

    This will do nothing if the user clicks the button while the MediaPlayer is still playing so it will continue with whatever it was playing. You could instead call mp.stop() and start the new sound file. That way instead of ignoring the click it would stop the current sound no matter how far into it we are and start the new one.

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

Sidebar

Related Questions

I have two view controllers. I'm on first, and when I press the button,
I have two windows in separate applications. The first application has a button that
This is what I want to accomplish. I have two buttons, when I press
I've got two forms. In the first, I have a textbox and a button,
The problem is that i have two forms. First is parent form, second is
I have this two uls: <ul actualpage=0 id=lastcompanieslist hideable=true upperpage=1> <li page=0 style=display: none;><img
ok, sorry. I have this two xml files. ProvlaLingua1.xml <VENDOR> <IMMAGINI_SITO>True</IMMAGINI_SITO> <VERSIONE_SKYWALKER>1</VERSIONE_SKYWALKER> <CDLINGUA>IT</CDLINGUA> </VENDOR>
Is there any way to have this: [one[two]][three] And extract this with a regex?
Why this two functions have the strange behaviour of when I click on thead,
having this two classes I always have a doubt of which is the best

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.