//音效的音量

  int streamVolume;

  //定义SoundPool 对象 private SoundPool soundPool;

  //定义HASH表 private HashMap<Integer, Integer> soundPoolMap;

  /*************************************************************** * Function: initSounds();

  * Parameters: null

  * Returns: None.

  * Description: 初始化声音系统

  * Notes: none.

  ***************************************************************/

  public void initSounds() { //初始化soundPool 对象,第一个参数是允许有多少个声音流同时播放,第2个参数是声音类型,第三个参数是声音的品质 soundPool = new SoundPool(100, AudioManager.STREAM_MUSIC, 100);

  //初始化HASH表 soundPoolMap = new HashMap<Integer, Integer>();

  //获得声音设备和设备音量 AudioManager mgr = (AudioManager)context.getSystemService(Context.AUDIO_SERVICE);

  streamVolume = mgr.getStreamVolume(AudioManager.STREAM_MUSIC);

  }

  /*************************************************************** * Function: loadSfx();

  * Parameters: null

  * Returns: None.

  * Description: 加载音效资源

  * Notes: none.

  ***************************************************************/

  public void loadSfx(int raw, int ID) { //把资源中的音效加载到指定的ID(播放的时候就对应到这个ID播放就行了) soundPoolMap.put(ID, soundPool.load(context, raw, ID));

  }

  /*************************************************************** * Function: play();

  * Parameters: sound:要播放的音效的ID, loop:循环次数

  * Returns: None.

  * Description: 播放声音

  * Notes: none.

  ***************************************************************/

  public void play(int sound, int uLoop)
{
soundPool.play(soundPoolMap.get(sound), streamVolume, streamVolume, 1, uLoop, 1f);
}

最新文章

  1. 使用Gson转换json数据为Java对象的一个例子
  2. Win10专业版激活永久可查激活信息
  3. springboot 添加job定时任务
  4. AC自动机 专题
  5. 教程-Delphi中Spcomm使用属性及用法详解
  6. QT皮肤框架-TQUI
  7. Android技术路线图
  8. Infix to posfix 自己写stack,没有()
  9. 解决编译时出现的警告:format string is not a string literal (potentially insecure)
  10. 动态规划1-----------poj1080
  11. Azure SQL Database (24) 使用新管理界面,创建跨数据中心标准地域复制(Standard Geo-Replication)
  12. SQL server中事务的四个属性特征(ACID)
  13. Akka Serialization
  14. 集合的综合练习:Poker牌
  15. android消息处理源码分析
  16. learning makefile call func
  17. python之路-----python操作 mysql
  18. saltstack高效运维
  19. pointcut 切面表达式 切入点表达式
  20. [模板][P3796]AC自动机(加强版)

热门文章

  1. Linux如何统计进程的CPU利用率
  2. Dapper.net 在Parameterized时对于String的扩展(转)
  3. HDU-3280 Equal Sum Partitions
  4. 读pomelo的教程-2
  5. 1.1&hellip;&hellip;什么是3G
  6. .net中的&quot;异步&quot;-手把手带你体验
  7. hdfs[命令] dfsadmin
  8. 如何在安裝SELinux的环境执行Quartus II
  9. linux 和 android 源码的 cross reference (即网页浏览代码的引用)
  10. Apache Spark Streaming的适用场景