How to Play two Different sound on two different buttons on OnTouchListner Android?

How to Play two Different sound on two different buttons on OnTouchListner Android?

I am making an android app. I have added two buttons and assigned two different sounds to them. Now the Button1 shoudl play sound.mp3 and Button2 should play asound.mp3 while press down and sound should be stop on press up. The problem is that both buttons are playing only one sound.

I am making an android app. I have added two buttons and assigned two different sounds to them. Now the Button1 shoudl play sound.mp3 and Button2 should play asound.mp3 while press down and sound should be stop on press up. The problem is that both buttons are playing only one sound.

package com.example.sound1;

import android.app.Activity; import android.media.MediaPlayer; import android.os.Bundle; import android.view.MotionEvent; import android.view.View; import android.view.View.OnTouchListener; import android.widget.ImageButton;

public class MainActivity extends Activity implements OnTouchListener {

private MediaPlayer mp;

public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main);

ImageButton btn = (ImageButton) this.findViewById(R.id.button1); btn.setOnTouchListener(this); mp = MediaPlayer.create(this, R.raw.sound);

ImageButton btn2 = (ImageButton) this.findViewById(R.id.button2); btn2.setOnTouchListener(this); mp = MediaPlayer.create(this, R.raw.asound); }

@Override public boolean onTouch(View v, MotionEvent event) { switch (event.getAction()) {

case MotionEvent.ACTION_DOWN: { mp.setLooping(true); mp.start(); }


Angular 9 Tutorial: Learn to Build a CRUD Angular App Quickly

What's new in Bootstrap 5 and when Bootstrap 5 release date?

Brave, Chrome, Firefox, Opera or Edge: Which is Better and Faster?

How to Build Progressive Web Apps (PWA) using Angular 9

What is new features in Javascript ES2020 ECMAScript 2020

Java Fundamentals: Learn Java for absolute beginners |Simpliv

Java Fundamentals: Learn Java for absolute beginners

Java Essentials : Learn Core Java From Basic to Advance

Learn Java Programming Using Practical Assignments. Start Building Back-end Web Applications Robust Test Automation Frameworks By End Of The Course. Learn More!

Android App Development Company in UAE

Have a plan to build an robust Android App Development with multiple features? We at Data EximIT is one of the best **[Android App Development Company in UAE](https://www.dataeximit.com/android-application-development/ "Android App Development...