package com.jlb.scan.util;

import android.content.Context;
import android.media.AudioManager;
import android.media.SoundPool;
import android.util.SparseIntArray; import com.jlb.scan.R; /**
* @version V1.0
* @Description: 语音提示的 辅助类
*/
public class MySoundAlertUtil {
public static final int GET_ORDER_INFO_REQUEST_CODE = 0x001;
public static final int STATUS_NORMAL = 10101; // 正常
public static final int STATUS_PICKUP = 10102;// 取走
public static final int STATUS_RETRIEVE = 10104;// 取回
public static final int STATUS_WITHDRAW = 10122;// 已退
public static final int STATUS_FLAG_WITHDRAW = 10124;// 待退
public static final int STATUS_NOEXIT = -10999;// 不存在
public static final int STATUS_OTHER = -10998;// 异常 /**
* 运单错误
*/
public static final int ERROR_yundan_cuowu = 11;
/**
* 运单重复
*/
public static final int ERROR_yundan_chongfu = 12;
/**
* 运单已接驳
*/
public static final int ERROR_yundan_yijiebo = 13;
/**
* 接驳成功
*/
public static final int JIEBO_SUCCESS = 14;// 异常 public static final int ERROR_JIEBO_PICI_INFO_ERROR = 15;// 批次信息错误,请重新选择
//运单不存在
public static final int ERROR_WAYBILL_NOT_EXIST = 16; //未知
public static final int ERROR_UNKNOW = 17; public static final int ERROR_NO_PHONE_NUM = 18; public static final int ERROR_NO_JIE_BO = 15351; private SoundPool mSoundPool;
private SparseIntArray mSoundMap;
private Context context; public MySoundAlertUtil(Context context) {
super();
this.context = context;
initSound(context);// ;
} private void initSound(Context context) {
mSoundPool = new SoundPool(10, AudioManager.STREAM_ALARM, 5);
mSoundMap = new SparseIntArray(20);
mSoundMap.put(STATUS_NORMAL, mSoundPool.load(context, R.raw.normal, 1));
mSoundMap.put(STATUS_PICKUP, mSoundPool.load(context, R.raw.finished, 1));
mSoundMap.put(STATUS_NOEXIT, mSoundPool.load(context, R.raw.noexist, 1));
mSoundMap.put(STATUS_OTHER, mSoundPool.load(context, R.raw.error, 1));
mSoundMap.put(STATUS_RETRIEVE, mSoundPool.load(context, R.raw.quhui, 1));
mSoundMap.put(STATUS_WITHDRAW, mSoundPool.load(context, R.raw.tuihui, 1));
mSoundMap.put(STATUS_FLAG_WITHDRAW, mSoundPool.load(context, R.raw.daitui, 1)); mSoundMap.put(ERROR_yundan_cuowu, mSoundPool.load(context, R.raw.yundan_cuowu, 1));
mSoundMap.put(ERROR_yundan_chongfu, mSoundPool.load(context, R.raw.yundan_chongfu, 1));
mSoundMap.put(ERROR_yundan_yijiebo, mSoundPool.load(context, R.raw.yundan_yijiebo, 1));
mSoundMap.put(JIEBO_SUCCESS, mSoundPool.load(context, R.raw.success, 1));
mSoundMap.put(ERROR_JIEBO_PICI_INFO_ERROR, mSoundPool.load(context, R.raw.pici_info_error, 1));
mSoundMap.put(ERROR_WAYBILL_NOT_EXIST, mSoundPool.load(context, R.raw.waybill_not_exist, 1));
mSoundMap.put(ERROR_NO_PHONE_NUM, mSoundPool.load(context, R.raw.no_phone_num, 1));
mSoundMap.put(ERROR_NO_JIE_BO, mSoundPool.load(context, R.raw.no_jie_bo, 1));
} public void play(int statusid) {
if (mSoundMap.indexOfKey(statusid) != -1) {
mSoundPool.play(mSoundMap.get(statusid), 1f, 1f, 0, 0, 1);
}
} public void release() {
if (mSoundPool != null) {
mSoundPool.release();
}
} /**
* 读取文件到 sound pool
*
* @param resourceKey
* @param filePath
*/
public void loadSoundFile(int resourceKey, String filePath) {
int id = mSoundPool.load(filePath, 1);
mSoundMap.put(resourceKey, id);
} /**
* 从资源文件加载音频
*
* @param key
* @param resouceID
*/
public void loadFromResource(int key, int resouceID) {
mSoundMap.put(key, mSoundPool.load(context, resouceID, 1));
} public boolean exist(int soundKey) {
return mSoundMap.indexOfKey(soundKey) > 0;
} public void delete(int soundKey) {
int soundID = mSoundMap.get(soundKey);
if (soundID > 0) {
mSoundPool.unload(soundID);
mSoundMap.delete(soundKey);
}
}
}

语音提示辅助类MySoundAlertUtil的更多相关文章

  1. FreeSWITCH在呼叫失败的情况下播放语音提示

    看到好多网友问到这个问题.一般我们在打电话时会听到“您拨的电话正在通话中,请稍后再拨....”,或“电话无应答...”之类的提示,我们在 freeswitch 里也可以这样做. 其实很简单,默认的配置 ...

  2. 微信小程序语音提示

    一. 老规矩, 先上demo图:  然后通过 wx.createInnerAudioContext  创建内部 audio 上下文 InnerAudioContext 对象 就能播放 filename ...

  3. asp.net引用System.Speech实现语音提示

    using System; using System.Speech.Synthesis; namespace testvoice { class Program { static void Main( ...

  4. 主攻ASP.NET.4.5.1 MVC5.0之重生:Web项目语音朗读网页文本,简单语音提示浏览状态

    第一步 添加SpeechLib.dll 下载SpeechLib.dll: 在项目中并且引用DLL using SpeechLib; using System.Threading; 第二步 调用并使用 ...

  5. C# winform语音提示

    1.SpeechSynthesizer文字转音频 项目添加引用:System.Speech using(SpeechSynthesizer speech = new SpeechSynthesizer ...

  6. python语音提示

    #coding:utf8 import win32com.client speaker = win32com.client.Dispatch("SAPI.SpVoice") whi ...

  7. iOS开发笔记10:圆点缩放动画、强制更新、远程推送加语音提醒及UIView截屏

    1.使用CAReplicatorLayer制作等待动画 CALayer+CABasicAnimation可以制作很多简单的动画效果,之前的博客中介绍的“两个动画”,一个是利用一张渐变色图片+CABas ...

  8. 烽火2640路由器命令行手册-11-IP语音配置命令

    IP语音配置命令 目  录 第1章 配置拨号对命令... 1 1.1 配置拨号对命令... 1 1.1.1 dial-peer voice. 1 1.1.2 application. 2 1.1.3 ...

  9. Xamarin Essentials教程语音播报TextToSpeech

    Xamarin Essentials教程语音播报TextToSpeech   语音播报是一种将文本信息转化为音频信息的技术.使用该技术,开发者可以让用户不用盯着屏幕,就可以获取到信息.例如,支付宝为商 ...

随机推荐

  1. 关于对GitHub的使用

    什么是GitHub? GitHub是版本控制和协作的代码托管平台.它可以让你在其他人在任何地方一起工作. 本文主要向您介绍GitHub essentials,如存储库,分支,提交和合并请求.将您创建自 ...

  2. iOS-delegate设计模式

    1. 使用场合 1> A想让B帮忙做一些事情,就让B成为A的代理 2> A想通知一下B发生了某些事情,或者想传递一些数据给B,就让B成为A的代理 3> B想监听A所做的一些事情, 就 ...

  3. 使用泛型类简化ibatis系统架构

    jdk1.5的推出为我们带来了枚举.泛型.foreach循环.同步工具包等等好东西.其中,泛型的使用为我们的代码开发提供了很大的简便,简化了我们的代码. 1.设计思路 1)GenericDao泛型类提 ...

  4. setBackgroundResource和setImageResource的区别

    setBackgroundResource是设置view的背景图片 setImageResource是设置ImageView的图片 对于一个imagevewButton来说,你既可以setBackgr ...

  5. ionic2升级到ionic3并打包APK

    通过IONIC2升级到3的时候,经过我一系列的测试,以及网上各种办法,现将新测有效的方法记录如下,本人按如下方法,对多个项目升级后,都能正常打包成APK IONIC 2到3的升级: 1.拷贝ionic ...

  6. 腾讯QQ空间穿越时光轴3D特效

    <DOCTYPE html> <html> <head> <title>腾讯QQ空间穿越光轴3D特效</title> <style&g ...

  7. 玩转Openstack之Nova中的协同并发(二)

    玩转Openstack之Nova中的协同并发(二) 昨天介绍了Python中的并发处理,主要介绍了Eventlet,今天就接着谈谈Openstack中Nova对其的应用. eventlet 在nova ...

  8. SQL Server VALUES 使用一记住

    VALUES 用得最多,最常见的就是 INSER INOT 表名(列名1,列名2,......) VALUES(值1,值2,......) ------------------------------ ...

  9. Microsxxxxxxx-面试总结

    策略题 There are four kinds of cards, respectively, 1,2, 3,4 numbers. There are seven cards for each ty ...

  10. 使用 JsonPath 完成接口自动化测试中参数关联和数据验证(Python语言)

    背景: 接口自动化测试实现简单.成本较低.收益较高,越来越受到企业重视 restful风格的api设计大行其道 json成为主流的轻量级数据交换格式 痛点: 接口关联 也称为关联参数.在应用业务接口中 ...