Commit 8225a90f by qyw

update 饭堂支付

parent 77725a94
......@@ -14,11 +14,11 @@ import java.util.HashMap;
public class SoundPlayUtils {
// SoundPool对象
public static SoundPool mSoundPlayer = new SoundPool(20,
AudioManager.STREAM_MUSIC, 5);
public static SoundPool mSoundPlayer;
public static SoundPlayUtils soundPlayUtils;
// 上下文
static Context mContext;
static boolean isOnLoadComplete = false;
private static HashMap<Integer, Integer> data = new HashMap<Integer, Integer>();
/**
......@@ -33,9 +33,12 @@ public class SoundPlayUtils {
}
// 初始化声音
mContext = context;
mSoundPlayer = new SoundPool(20,
AudioManager.STREAM_MUSIC, 5);
/**
* 参数1:加载音乐流第多少个 (只用了俩个音乐) 2:设置音乐的质量 音乐流 3:资源的质量 0
*/
isOnLoadComplete = false;
data.put(200, mSoundPlayer.load(mContext, R.raw.success, 1));
data.put(1, mSoundPlayer.load(mContext, R.raw.fail, 1));
data.put(500, mSoundPlayer.load(mContext, R.raw.s500, 1));
......@@ -54,6 +57,12 @@ public class SoundPlayUtils {
data.put(513, mSoundPlayer.load(mContext, R.raw.s513, 1));
data.put(514, mSoundPlayer.load(mContext, R.raw.s514, 1));
data.put(515, mSoundPlayer.load(mContext, R.raw.s515, 1));
mSoundPlayer.setOnLoadCompleteListener(new SoundPool.OnLoadCompleteListener() {
@Override
public void onLoadComplete(SoundPool soundPool, int i, int i1) {
isOnLoadComplete = true;
}
});
return soundPlayUtils;
}
......@@ -63,6 +72,12 @@ public class SoundPlayUtils {
* @param soundID 设置声音
*/
public static void play(int soundID) {
if (!isOnLoadComplete) {
return;
}
if (mSoundPlayer == null) {
return;
}
if (data.containsKey(soundID)) {
mSoundPlayer.play(data.get(soundID), 1, 1, 0, 0, 1);
} else {
......@@ -71,7 +86,11 @@ public class SoundPlayUtils {
}
public static void release() {
mSoundPlayer.release();
if (mSoundPlayer != null) {
mSoundPlayer.release();
}
soundPlayUtils = null;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment