• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Sound Pool and Hash Map

raamkum

Lurker
Hi,

I have approximately 100 audio files in the raw folder this 100 files are just says numbers from 1 to 100.

After I click on a button. I want it to play the number according to the text entered in the text box.

So I use sound pool and hash map for it. This works just fine without any issues

Code:
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));
...... like that till 100

I fetch the value of the text field

I put a for loop from 1 to 100.

what ever the value will be played.

using the soundPool.play(1,....)

This works just fine without any issue.

But strange thing in this is that since it is creating haspmap of 100 value.. there is 5 seconds delay and with blank screen and I can't do anything with process is going on.

Is there any way to just create hashmap according to the value and plays the sound.

Like say for e.g

If text field has value 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,....)

if the above is possible... How do I do it?

Awaiting your response!
Thanks!
 
Back
Top Bottom