Android Question [Solved] Sound Pool loading delay.

vfafou

Well-Known Member
Licensed User
Longtime User
Hello!
I'm trying to load ~180 ogg files to the sound pool of audio library. Some devices do it within 1 second but for some others there is a delay of 30-50 seconds.
I think I have to load them asynchronously but there is not any method in library to allow this.
What else could I do?

Thank you in advance!
 

vfafou

Well-Known Member
Licensed User
Longtime User
Hello stevel05!
Thank you for the very fast response!
The delay is appeared in both modes.
During the loading, the UI stops responding, but I don't want to put a DoEvents!
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
I am out for the rest of the day, if you don't get another answer I'll take a look this evening, but can you post your loading code. It will help us to help you.
 
Upvote 0

vfafou

Well-Known Member
Licensed User
Longtime User
I am out for the rest of the day, if you don't get another answer I'll take a look this evening, but can you post your loading code. It will help us to help you.
OK, my code is similar to:
B4X:
For i = 1 to 180
  SMap.Put(i & "Normal.ogg",SndPool.Load(i & "Normal.ogg"))
Next
I put the LoadId in a map using the file name as key.
 
Upvote 0

vfafou

Well-Known Member
Licensed User
Longtime User
Maybe load the files when they are first needed:
B4X:
Sub GetAudioId(Name As String) As Int
If SMap.ContainsKey(Name) = False Then Smap.Put(Name, SndPool.Load(...))
Return Smap.Get(Name)
End Sub
Hi, Erel!
Thank you for your brain-unstucking instructions! You help is brilliantly precious!
 
Upvote 0

vfafou

Well-Known Member
Licensed User
Longtime User
Detected a problem! When I first put an object to the map, there's no sound playing. I think it doesn't load the files so fast!
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
Check the link in post #2, it provides a method to get a callback when the file is loaded.
 
Upvote 0
Top