【问题标题】:Sample not ready soundpool样品未准备好 soundpool
【发布时间】:2013-05-24 09:00:05
【问题描述】:

我正在开发一个将短语从英语翻译成另一种语言的应用程序。我正在使用 ExpandableListView 并通过 BaseExpandableListAdapter 绑定数据。简而言之:当单击列表项时,会打开一个子项,您可以在其中看到翻译,同时有声音在说话。 问题是不时播放声音 - 特别是对于较长的乐句。我在 logcat 中可以看到以下内容:

1) 当声音根本没有播放时...

样本未加载。等待 30 毫秒。 样本 X 尚未准备好

2) 实际播放声音时

*样品未加载。等待 30 毫秒。


所以即使播放了声音,logcat 也会告诉“样本尚未准备好”。

好的,这就是 logcat 给出的信息。另一件事是,对于较大的声音文件,失败的可能性更大。小声音文件播放两秒钟(约 30 KB) 和更大的约 4 秒(约 60 KB)。

现在我不知道如何解决这个问题。我在互联网上搜索了解决方案,尤其是这个网站。我都尝试过....

1) 使用 OnLoadCompleteListener()

及其不工作

2) 制作某种 while 循环。

也不行

我可能做错了什么。我在下面给出代码。也许有些尴尬?例如,我是否以错误的方式实现了监听器?

真诚的

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 OnLoadCompleteListener() {
                  @Override
                  public void onLoadComplete(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);
                }
            }
        }
    }); 

【问题讨论】:

    标签: android soundpool


    【解决方案1】:

    我认为您应该将代码更改如下:

     myVoice = soundPool.load(PhraseActivity.this, sound[group_position][0], 2);
            soundPool.setOnLoadCompleteListener(new OnLoadCompleteListener() {
                  @Override
                  public void onLoadComplete(SoundPool soundPool, int sampleId,
                      int status) {
                        soundPool.play(myVoice, 20, 20, 1, 0, 1f);
                  } 
            });
    

    它对我有用。

    【讨论】:

    • 它似乎工作正常。今天会尝试更多,但我现在可以说的是它好多了。非常感谢你:-) :-)
    猜你喜欢
    • 2011-07-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多