制作安卓软件怎样添加背景音乐?

%title插图%num

制作安卓软件怎样添加背景音乐?

在需要的地方调用即可
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
});
}