【发布时间】:2012-06-08 04:46:31
【问题描述】:
我在原始文件夹中有大约 100 个音频文件,这 100 个文件只是表示从 1 到 100 的数字。
点击按钮后。我希望它根据文本框中输入的文本播放号码。
所以我使用声音池和哈希映射。这工作得很好,没有任何问题
soundPool = new SoundPool(1, AudioManager.STREAM_MUSIC, 100);
soundsMap = new HashMap<Integer, Integer>();
soundsMap.put(1, soundPool.load(this, R.raw.number1, 1));
soundsMap.put(2, soundPool.load(this, R.raw.number2, 1));
像上面一样直到 number100。我获取文本字段的值
我放了一个从 1 到 100 的 for 循环。播放的值是什么。
使用 soundPool.play(1,....)
这很好用,没有任何问题。
但奇怪的是,由于它正在创建 100 值的 haspmap.. 有 5 秒的延迟和空白屏幕,我无法对进程进行任何操作。
有什么方法可以根据值创建hashmap并播放声音。
例如说例如
如果文本字段的值为 20
in the for loop: i=1 to 100..
it should get the value 20:
string a = "R.raw.number"+i
SoundsMap.put(1, soundPool.load(this, a, 1));
soundPool.play(1,....)
如果以上是可能的...我该怎么做?
等待您的回复! 谢谢!
【问题讨论】:
-
我不知道你为什么觉得这很奇怪。您正在加载 100 个音频文件。这需要时间。您可以在后台线程中执行此操作(可能使用
AsyncTask)并在加载时显示进度条。我不清楚你用你的 for 循环做什么。 -
天哪,你是在循环 100 次测试
if(editText.getText().equals(String.valueOf(i)))吗?诺诺诺诺。将输入解析为一个数字,然后从那里开始。检查下面的示例。