【项目实例】android开发游戏音效代码实例
2024-08-27 06:16:15
//音效的音量 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);
}
最新文章
- 使用Gson转换json数据为Java对象的一个例子
- Win10专业版激活永久可查激活信息
- springboot 添加job定时任务
- AC自动机 专题
- 教程-Delphi中Spcomm使用属性及用法详解
- QT皮肤框架-TQUI
- Android技术路线图
- Infix to posfix 自己写stack,没有()
- 解决编译时出现的警告:format string is not a string literal (potentially insecure)
- 动态规划1-----------poj1080
- Azure SQL Database (24) 使用新管理界面,创建跨数据中心标准地域复制(Standard Geo-Replication)
- SQL server中事务的四个属性特征(ACID)
- Akka Serialization
- 集合的综合练习:Poker牌
- android消息处理源码分析
- learning makefile call func
- python之路-----python操作 mysql
- saltstack高效运维
- pointcut 切面表达式 切入点表达式
- [模板][P3796]AC自动机(加强版)
热门文章
- Linux如何统计进程的CPU利用率
- Dapper.net 在Parameterized时对于String的扩展(转)
- HDU-3280 Equal Sum Partitions
- 读pomelo的教程-2
- 1.1&hellip;&hellip;什么是3G
- .net中的";异步";-手把手带你体验
- hdfs[命令] dfsadmin
- 如何在安裝SELinux的环境执行Quartus II
- linux 和 android 源码的 cross reference (即网页浏览代码的引用)
- Apache Spark Streaming的适用场景