大佬教程收集整理的这篇文章主要介绍了java – 同时播放声音Android,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
public class SoundManager { private SoundPool mSoundPool; private HashMap<Integer,Integer> mSoundPoolMap; private Au@L_772_7@manager mAu@L_772_7@manager; private Context mContext; public SoundManager(Context theContext) { mContext = theContext; mSoundPool = new SoundPool(4,Au@L_772_7@manager.STREAM_MUSIC,0); mSoundPoolMap = new HashMap<Integer,Integer>(); mAu@L_772_7@manager = (Au@L_772_7@manager) mContext.getSystemservice(Context.AU@L_772_7@_serviCE); } public void addSound(int index,int SoundID) { mSoundPoolMap.put(index,mSoundPool.load(mContext,SoundID,1)); } public void playSound(int indeX) { float streamVolume = mAu@L_772_7@manager.getStreamVolume(Au@L_772_7@manager.STREAM_RING); streamVolume = streamVolume / mAu@L_772_7@manager.getStreAMMaxVolume(Au@L_772_7@manager.STREAM_RING); mSoundPool.play((Integer) mSoundPoolMap.get(indeX),streamVolume,1,1f); } public void playLoopedSound(int indeX) { float streamVolume = mAu@L_772_7@manager.getStreamVolume(Au@L_772_7@manager.STREAM_MUSIC); streamVolume = streamVolume / mAu@L_772_7@manager.getStreAMMaxVolume(Au@L_772_7@manager.STREAM_MUSIC); mSoundPool.play((Integer) mSoundPoolMap.get(indeX),-1,1f); } }
SoundManager sm = new SoundManager(this); sm.addSound(0,R.raw.explosion); sm.playSound(0);
…所以用这种风格,我把所有的声音添加到SoundPool上,然后根据用户输入,我只想播放声音.这看起来正确吗?或者我应该尝试不同的方法吗?
需要改变,以允许更多的流在同一时间播放.所以通过将第一个参数从4改为20,然后可以同时播放20个声音.这个游戏听起来好多了,哈哈.希望这有助于某人.
以上是大佬教程为你收集整理的java – 同时播放声音Android全部内容,希望文章能够帮你解决java – 同时播放声音Android所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。