xxxxxxxxxx
public class MusicPlayer extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);
// Find the Button from the xml-file.
Button cmd_play = (Button)this.findViewById(R.id.cmd_play);
cmd_play.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View arg0) {
MediaPlayer mp = MediaPlayer.create(MusicPlayer.this,
R.raw.everlast);
mp.prepare();
mp.start();
// i.e. react on the end of the music-file:
mp.setOnCompletionListener(new OnCompletionListener(){
// @Override
public void onCompletion(MediaPlayer arg0) {
// File has ended !!!
Toast.makeText(context, "Media Completed with Success", Toast.LENGTH_SHORT).show();
}
});
}
});
}
}