package com.example.media; import android.graphics.Color; import android.media.MediaPlayer; import android.os.Bundle; import android.app.Activity; import android.view.Menu; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; public class MainActivity extends Activity { private MediaPlayer mediaPlayer; private Button btn; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); btn=(Button)findViewById(R.id.btn); btn.setOnClickListener(new OnClickListener() { public void onClick(View view) { try { playAudio(); view.setBackgroundColor(Color.RED); } catch(Exception e) { e.printStackTrace(); } } }); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } private void playAudio() throws Exception { mediaPlayer=MediaPlayer.create(this,R.raw.ms); mediaPlayer.start(); } }