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) {
// res/raw 폴더내에 sound_file 파일을 추가해놓음.
MediaPlayer mp = MediaPlayer.create(MusicPlayer.this,
R.raw.sound_file);
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 !!! Wink
}
});
}
});
}
}