package cn.jlb.pro.intelligentcabinet.library.sound;
import android.content.Context;
import android.media.AudioManager;
import android.media.SoundPool;
import android.util.SparseIntArray;
import cn.jlb.pro.intelligentcabinet.R;
import cn.jlb.pro.intelligentcabinet.app.BoxApp;
import cn.jlb.pro.intelligentcabinet.config.Constants;
/**
* 语音提示,辅助类,invoke 方式: AlarmSoundUtil.getInstance().play(AlarmSoundUtil.KEY_input_your_number);
* <p/>
* Created by zhangyunfei on 15/9/15.
*/
public class AlarmSoundUtil {
public static final int KEY_input_your_number = 101;
public static final int KEY_selectgekou = 103;
public static final int KEY_selectchongzhi = 104;
public static final int KEY_please_input_pickup_password = 105;
public static final int KEY_sao = 107;
public static final int KEY_closebox = 108;
public static final int KEY_please_input_consignee_phone = 109;
public static final int KEY_open_box_error = 110;
public static final int KEY_deliver_closebox = 111;
public static final int KEY_finishe = 112;
public static final int KEY_CHONGZHI_JIN_E = 113;
public static final int KEY_TOU_BI = 114;
public static final int KEY_TOU_BI_2 = 115;
public static final int KEY_DU = 118;
//请输入取件密码
public static final int KEY_please_input_waybill = 116;
//请输入手机号码和动态密码
public static final int KEY_please_input_phone_and_dynamicpassword = 117;
/**
* 数字语音的开始位置:后续位置即 KEY_NUMBER_START + n ,n = 0,1,2,3...
*/
public static final int KEY_NUMBER_0 = 201509150;
public static final int KEY_NUMBER_1 = 201509151;
public static final int KEY_NUMBER_2 = 201509152;
public static final int KEY_NUMBER_3 = 201509153;
public static final int KEY_NUMBER_4 = 201509154;
public static final int KEY_NUMBER_5 = 201509155;
public static final int KEY_NUMBER_6 = 201509156;
public static final int KEY_NUMBER_7 = 201509157;
public static final int KEY_NUMBER_8 = 201509158;
public static final int KEY_NUMBER_9 = 201509159;
private static AlarmSoundUtil mInstance;
private SoundPool soundPool;
private SparseIntArray soundMap;
public static AlarmSoundUtil getInstance() {
if (mInstance == null) {
mInstance = new AlarmSoundUtil(BoxApp.getApp());
}
return mInstance;
}
private AlarmSoundUtil(Context context) {
soundPool = new SoundPool(1, AudioManager.STREAM_ALARM, 5);
soundMap = new SparseIntArray();
load(context);
}
private void load(Context context) {
if (Constants.DEBUG)
return;
soundMap.put(KEY_NUMBER_0, soundPool.load(context, R.raw.number_0, 1));
soundMap.put(KEY_NUMBER_1, soundPool.load(context, R.raw.number_1, 1));
soundMap.put(KEY_NUMBER_2, soundPool.load(context, R.raw.number_2, 1));
soundMap.put(KEY_NUMBER_3, soundPool.load(context, R.raw.number_3, 1));
soundMap.put(KEY_NUMBER_4, soundPool.load(context, R.raw.number_4, 1));
soundMap.put(KEY_NUMBER_5, soundPool.load(context, R.raw.number_5, 1));
soundMap.put(KEY_NUMBER_6, soundPool.load(context, R.raw.number_6, 1));
soundMap.put(KEY_NUMBER_7, soundPool.load(context, R.raw.number_7, 1));
soundMap.put(KEY_NUMBER_8, soundPool.load(context, R.raw.number_8, 1));
soundMap.put(KEY_NUMBER_9, soundPool.load(context, R.raw.number_9, 1));
}
/**
* 音频资源ID 播放语音
*
* @param key 音频资源ID
*/
public void play(int key) {
if (soundPool == null) return;
if (Constants.DEBUG)
return;
soundPool.play(soundMap.get(key), 1, 1, 0, 0, 1);
}
import android.content.Context;
import android.media.AudioManager;
import android.media.SoundPool;
import android.util.SparseIntArray;
import cn.jlb.pro.intelligentcabinet.R;
import cn.jlb.pro.intelligentcabinet.app.BoxApp;
import cn.jlb.pro.intelligentcabinet.config.Constants;
/**
* 语音提示,辅助类,invoke 方式: AlarmSoundUtil.getInstance().play(AlarmSoundUtil.KEY_input_your_number);
* <p/>
* Created by zhangyunfei on 15/9/15.
*/
public class AlarmSoundUtil {
public static final int KEY_input_your_number = 101;
public static final int KEY_selectgekou = 103;
public static final int KEY_selectchongzhi = 104;
public static final int KEY_please_input_pickup_password = 105;
public static final int KEY_sao = 107;
public static final int KEY_closebox = 108;
public static final int KEY_please_input_consignee_phone = 109;
public static final int KEY_open_box_error = 110;
public static final int KEY_deliver_closebox = 111;
public static final int KEY_finishe = 112;
public static final int KEY_CHONGZHI_JIN_E = 113;
public static final int KEY_TOU_BI = 114;
public static final int KEY_TOU_BI_2 = 115;
public static final int KEY_DU = 118;
//请输入取件密码
public static final int KEY_please_input_waybill = 116;
//请输入手机号码和动态密码
public static final int KEY_please_input_phone_and_dynamicpassword = 117;
/**
* 数字语音的开始位置:后续位置即 KEY_NUMBER_START + n ,n = 0,1,2,3...
*/
public static final int KEY_NUMBER_0 = 201509150;
public static final int KEY_NUMBER_1 = 201509151;
public static final int KEY_NUMBER_2 = 201509152;
public static final int KEY_NUMBER_3 = 201509153;
public static final int KEY_NUMBER_4 = 201509154;
public static final int KEY_NUMBER_5 = 201509155;
public static final int KEY_NUMBER_6 = 201509156;
public static final int KEY_NUMBER_7 = 201509157;
public static final int KEY_NUMBER_8 = 201509158;
public static final int KEY_NUMBER_9 = 201509159;
private static AlarmSoundUtil mInstance;
private SoundPool soundPool;
private SparseIntArray soundMap;
public static AlarmSoundUtil getInstance() {
if (mInstance == null) {
mInstance = new AlarmSoundUtil(BoxApp.getApp());
}
return mInstance;
}
private AlarmSoundUtil(Context context) {
soundPool = new SoundPool(1, AudioManager.STREAM_ALARM, 5);
soundMap = new SparseIntArray();
load(context);
}
private void load(Context context) {
if (Constants.DEBUG)
return;
soundMap.put(KEY_NUMBER_0, soundPool.load(context, R.raw.number_0, 1));
soundMap.put(KEY_NUMBER_1, soundPool.load(context, R.raw.number_1, 1));
soundMap.put(KEY_NUMBER_2, soundPool.load(context, R.raw.number_2, 1));
soundMap.put(KEY_NUMBER_3, soundPool.load(context, R.raw.number_3, 1));
soundMap.put(KEY_NUMBER_4, soundPool.load(context, R.raw.number_4, 1));
soundMap.put(KEY_NUMBER_5, soundPool.load(context, R.raw.number_5, 1));
soundMap.put(KEY_NUMBER_6, soundPool.load(context, R.raw.number_6, 1));
soundMap.put(KEY_NUMBER_7, soundPool.load(context, R.raw.number_7, 1));
soundMap.put(KEY_NUMBER_8, soundPool.load(context, R.raw.number_8, 1));
soundMap.put(KEY_NUMBER_9, soundPool.load(context, R.raw.number_9, 1));
}
/**
* 音频资源ID 播放语音
*
* @param key 音频资源ID
*/
public void play(int key) {
if (soundPool == null) return;
if (Constants.DEBUG)
return;
soundPool.play(soundMap.get(key), 1, 1, 0, 0, 1);
}
}
//调用
NumberSoundPlayer.ifNumber_playAlarmSound(primaryCode);