在您需要的地方调用即可
private MediaPlayer mMediaPlayer;
private void playLocalFile() {
mMediaPlayer = MediaPlayer.create(this, R.raw.in_call_alarm);
//播放工程res目录下的raw目录中的音乐文件in_call_alarm
try {
mMediaPlayer.prepare();
} catch (IllegalStateException e) {
} catch (IOException e) {
}
mMediaPlayer.start();
headsetplay.setEnabled(false);
mMediaPlayer.setOnCompletionListener(new OnCompletionListener() {
public void onCompletion(MediaPlayer mp) {
//播完了接着播或者关闭mMediaPlayer
});
}