Answers for "Android play sound on button click example"

1

play sound on button click android studio

Button one = (Button) this.findViewById(R.id.button1);
final MediaPlayer mp = MediaPlayer.create(this, R.raw.soho);
one.setOnClickListener(new OnClickListener(){

    public void onClick(View v) {
        mp.start();
    }
});
Posted by: Guest on April-09-2020
0

android play music on button click

public class MainActivity extends AppCompatActivity{
	Button bt;
	
	@Override
	protected void onCreate(Bundle savedInstanceState){
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		bt = (Button)findViewById(R.id.clickme);
		final MediaPlayer mp = MediaPlayer.create(this, R.raw.sample);
		bt.setOnClickListener(new View.OnClickListener(){
			@Overridepublic void onClick(View view){
				np.start();
			}
		}
	}
}
Posted by: Guest on March-18-2021

Code answers related to "Android play sound on button click example"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language