BG:当一个应用需要频繁使用某个短促音效的时候。


开发简介

创建SoundPool.SoundPool(int count,int soundType,int srcQuality)指定池的大小,声音类型,质量。

调用该对象的load()方法,其参数跟MediaPlayer差不多,最后一个参数int Priority暂时没有意义,默认写1。

调用play(int resourceID,float leftVolume,float rightolume,int priority,int loop,float rate)

对于多个资源 最好使用HashMap<Integer,Integer>加载

loop: 0表示没有循环 -1表示循环

rate:范围为 0.5-2

SoundPool soundPool=null;
//init pool
soundPool=new SoundPool(5,AudioManager.STREAM_MUSIC,0);
HashMap<Integer, Integer> soundMap=new HashMap<Integer, Integer>();
//padding data in soundMap
soundMap.put(1,soundPool.load(this,R.raw.song, 1));
//play
soundPool.play(soundMap.get(1),1,1,0,0,1);