
我正在开发一个将短语从英语翻译成另一种语言的应用程序.我使用ExpandableListVIEw和通过Baseexpandablelistadapter绑定数据.简而言之:当点击一个Listitem时,会打开一个子项目,您可以在其中看到翻译,同时发出语音.问题是偶尔会播放声音 – 特别是对于较长的短语.我在logcat中看到的内容如下:@H_403_1@
1)当声音没有播放时……@H_403_1@
样品未加载.等待30毫秒.
样品X未准备好@H_403_1@
2)当声音实际播放时@H_403_1@
*未加载样品.等待30毫秒.@H_403_1@
因此,即使播放声音,logcat也会告诉“样品没有准备好”.@H_403_1@
好的,这是logcat给出的信息.另一件事是,对于较大的声音文件,失败的概率更大.小型声音文件播放两秒钟(约30 KB)
大约4秒(约60 KB).@H_403_1@
现在我无法弄清楚如何解决这个问题.我在网上寻找解决方案,尤其是这个网站.我都试过……@H_403_1@
1)使用OnLoadCompleteListener()@H_403_1@
它不工作@H_403_1@
2)制作某种while循环.@H_403_1@
也不工作@H_403_1@
我有什么不对的.我给出下面的代码.也许有些尴尬?我是否以错误的方式实现了侦听器?@H_403_1@
Cincerely@H_403_1@
@H_403_1@
expList.setonGroupExpandListener(new OnGroupExpandListener() { public voID onGroupExpand(int groupposition) { final int group_position = groupposition; loaded = false; int nmbr_childs = adapter.getChildrenCount(groupposition); if (nmbr_childs == 1) { myVoice = soundPool.load(PhraseActivity.this, sound[group_position][0], 2); soundPool.setonLoadCompleteListener(new onl oadCompleteListener() { @OverrIDe public voID onl oadComplete(SoundPool soundPool, int sampleID, int status) { loaded = true; } }); if (loaded) { soundPool.play(myVoice, 20, 20, 1, 0, 1f); } else { System.out.println("something wrong with soundpool!"); } } group = groupposition; int len = adapter.getGroupCount(); for (int i = 0; i < len; i++) { if (i != groupposition) { expList.collapseGroup(i); } } } }); 解决方法:@H_403_1@
我认为您应该按如下方式更改代码:@H_403_1@
@H_403_1@
myVoice = soundPool.load(PhraseActivity.this, sound[group_position][0], 2); soundPool.setonLoadCompleteListener(new onl oadCompleteListener() { @OverrIDe public voID onl oadComplete(SoundPool soundPool, int sampleID, int status) { soundPool.play(myVoice, 20, 20, 1, 0, 1f); } });它对我有用.@H_403_1@ 总结
以上是内存溢出为你收集整理的android – 示例未准备好的soundpool全部内容,希望文章能够帮你解决android – 示例未准备好的soundpool所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)