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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T09:42:32+00:00 2026-06-03T09:42:32+00:00

I made a project where two textviews are on screen.I set two audio for

  • 0

I made a project where two textviews are on screen.I set two audio for the two textview with Ontouch method.So when i touch any of the textview it play the sound.
Here is the code

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final TextView tv = (TextView) findViewById(R.id.CustomFontText);
TextView tv1 = (TextView) findViewById(R.id.CustomFontText1);
Typeface tf = Typeface.createFromAsset(getAssets(),
"fonts/DroidSansFallback.ttf");
Typeface tf1 = Typeface.createFromAsset(getAssets(),
"fonts/DroidSans.ttf");
tv.setTypeface(tf);
tv1.setTypeface(tf1);

tv.setOnTouchListener(new OnTouchListener() {
   @Override
   public boolean onTouch(View v, MotionEvent event)   
   {  
       if(event.getAction() == MotionEvent.ACTION_DOWN)  
       {  
           if( v == findViewById( R.id.CustomFontText ))
           {
               MediaPlayer mp=MediaPlayer.create(getBaseContext(), R.raw.robotrock);
                mp.start();
       }  
       return false;  
   }
    return false;  
   }

       });  
 tv1.setOnTouchListener(new OnTouchListener() {
   @Override
   public boolean onTouch(View v, MotionEvent event)   
   {  
       if(event.getAction() == MotionEvent.ACTION_DOWN)  
       {  
           if( v == findViewById( R.id.CustomFontText1 ))
           {
               MediaPlayer mp1=MediaPlayer.create(getBaseContext(), R.raw.nam);
            mp1.start();
           }
       }  
       return false;  
   }  

       });
  }}

That is how i did it.The problem is when i touch both the textview,both audio play at the same time.
But I want when i touch one textview ,the audio will play and at that time if i touch another ,the previous audio need to stop and play the corresponding audio which textview is touched.So how can i handle them?Where i need to implement or edit my code?

Please HELP!!!

  • 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-03T09:42:33+00:00Added an answer on June 3, 2026 at 9:42 am

    I think you have already created two instaces of media player. What you have to do is to check for which is playing and stop it.

    tv.setOnTouchListener(new OnTouchListener() {
       @Override
       public boolean onTouch(View v, MotionEvent event)   
       {  
           if(event.getAction() == MotionEvent.ACTION_DOWN)  
           {  
               if( v == findViewById( R.id.CustomFontText ))
               {
                   MediaPlayer mp=MediaPlayer.create(getBaseContext(), R.raw.robotrock);
                   if (mp1 != null && mp1.isPlaying()) {
                       mp1.stop();
                   }
                    mp.start();
           }  
           return false;  
       }
        return false;  
       }
    
           });  
     tv1.setOnTouchListener(new OnTouchListener() {
       @Override
       public boolean onTouch(View v, MotionEvent event)   
       {  
           if(event.getAction() == MotionEvent.ACTION_DOWN)  
           {  
               if( v == findViewById( R.id.CustomFontText1 ))
               {
                   MediaPlayer mp1=MediaPlayer.create(getBaseContext(), R.raw.nam);
                   if (mp != null && mp.isPlaying()) {
                       mp.stop();
                   }
                mp1.start();
               }
           }  
           return false;  
       }  
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I made a poject where two audio play using touch with the two different
I have made a project in which i have added a splash screen by
I made a small project with Northwind database to illustrate the problematic. Here is
here I uploaded my Android project made in Eclipse. The idea is that i
Ok so I have a small project with two different scaffoldings I've made.In the
I have made two targets in my project. One for a Staging version and
Here is how I made a universal app from an existing iPhone project by
I have two view controllers named view1ViewController and view2ViewController in an cocoa touch project,
I learning Perl and doing a home made project to my family (a subscription
If I made a project with flex, and i want to distribute it, what

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.