Android音效SoundPool问题:soundpool 1 not retry
来源:互联网 发布:php前端要用到dw吗 编辑:程序博客网 时间:2024/05/16 10:53
Android音效SoundPool问题:soundpool 1 not retry
今天开发中要用到SoundPool,遇到soundpool 1 not retry无法播放声音,MediaPlay可以
后来经过一番研究,发现:
出现soundpool 1 not retry问题的代码,无法播放声音
mgr = (AudioManager) MainActivity.this.getSystemService(Context.AUDIO_SERVICE);
//初始化soundPool 对象,第一个参数是允许有多少个声音流同时播放,第2个参数是声音类型,第三个参数是声音的品质
soundPool = new SoundPool(4, AudioManager.STREAM_MUSIC, 100);
soundPoolMap = new HashMap<Integer, Integer>();
soundPoolMap.put(1, soundPool.load(MainActivity.this, R.raw.or, 1));
soundPoolMap.put(2, soundPool.load(MainActivity.this, R.raw.sd, 1));
volume = mgr.getStreamVolume(AudioManager.STREAM_MUSIC);
//loop:循环中的循环模式(0 =没有循环,-1 =无限循环)
soundPool.play(soundPoolMap.get(1), volume, volume, 1, 0, 1f);
问题解决:这里的问题是soundPool.load(MainActivity.this, R.raw.or, 1),即 load() 声音文件后,立马 play() 播放,系统还没有准备好声音文件,所以才出了问题
这里需要你:先在其他地方load()好了,比如在构造函数里先load()好了,在需要播放的地方再调用play(),也就是要过一段时间再调用play()
这样写就没问题
mgr = (AudioManager) MainActivity.this.getSystemService(Context.AUDIO_SERVICE);
//初始化soundPool 对象,第一个参数是允许有多少个声音流同时播放,第2个参数是声音类型,第三个参数是声音的品质
soundPool = new SoundPool(4, AudioManager.STREAM_MUSIC, 100);
soundPoolMap = new HashMap<Integer, Integer>();
soundPoolMap.put(1, soundPool.load(MainActivity.this, R.raw.or, 1));
soundPoolMap.put(2, soundPool.load(MainActivity.this, R.raw.sd, 1));
volume = mgr.getStreamVolume(AudioManager.STREAM_MUSIC);
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
soundPool.play(soundPoolMap.get(1), volume, volume, 1, 0, 1f);
- Android音效SoundPool问题:soundpool 1 not retry
- android SoundPool 音效播放
- Android 即时音效SoundPool
- android SoundPool播放音效
- android SoundPool 音效播放
- Android 音效 SoundPool
- Android应用:SoundPool 播放音效
- android 游戏音效播放 SoundPool
- android SoundPool播放音效(一)
- android SoundPool播放音效(二)
- Android用SoundPool播放音效
- Android之SoundPool播放音效
- Android 使用SoundPool播放音效
- Android SoundPool即时音效的使用Demo
- Android 多媒体:SoundPool—简短小音效
- android使用SoundPool 播放短音效
- android开发--音效音频播放SoundPool
- 【Android】播放音效——SoundPool
- configure脚本的输出
- linux 下基于jrtplib库的实时传送实现【转】
- PowerDesigner使用教程|使用方法
- Cache Manifest配置实例
- window server 2012 更改密钥 更改系统序列号
- Android音效SoundPool问题:soundpool 1 not retry
- 你所期待的一生
- Java中的方法重写和方法重载
- c++ static变量
- Android中,Context,什么是Context?
- 条码扫描二维码扫描——ZXing android 源码简化
- JMeter:Linux上安装&运行JMeter
- Qt 出现“undefined reference to `vtable for”原因总结
- 神奇的afxoleinit()