1、声明成员变量
private SoundPool mSp;
private int mSoundId;
2、初始化工作
//参数new SoundPool(int maxStreams, int streamType, int srcQuality)
mSp = new SoundPool(10, AudioManager.STREAM_MUSIC,5);
//参数load(Context context, int resId, int priority)
mSoundId = mSp.load(this, R.raw.ring, 1);
3、调用播放声音
//参数 play(int soundID, float leftVolume, float rightVolume, int priority, int loop, float rate)
mSp.play(mSoundId, 1, 1, 0, 0, 1);
注:初始化工作提前初始化以给足初始化时间,不可与播放声音一起调用,否则没效果。