1 回答
TA贡献2080条经验 获得超4个赞
播放声音并不困难。只要这些是应用程序前台操作期间的简短声音就可以了。您需要使用 MediaPlayer。首先,准备它。
private MediaPlayer mMediaPlayer = null;
private MediaPlayer.OnCompletionListener mOnCompletionListener = new MediaPlayer.OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mediaPlayer) {
if (mMediaPlayer != null) {
mMediaPlayer.release();
mMediaPlayer = null;
}
}
};
现在点击:
public void onItemClick(.........) {
releaseMediaPlayer();
mMediaPlayer = MediaPlayer.create(getActivity(),getSoundFileResID());
mMediaPlayer.setOnCompletionListener(mOnCompletionListener);
mMediaPlayer.start();
}
您需要实现 getSoundFileResID()。有关更多信息,请阅读MediaPlayer OverView
添加回答
举报