vfafou Well-Known Member Licensed User Longtime User Mar 30, 2017 #1 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!
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!
stevel05 Expert Licensed User Longtime User Mar 30, 2017 #2 If I remember correctly the sounds are already loaded asynchronously, you can implement a callback using Javaobject when the load is complete, There is an example in this thread: https://www.b4x.com/android/forum/threads/multitrigger-soundpool-example.42038/ How are you loading the sounds? Is there a delay in Debug or release mode? Upvote 0
If I remember correctly the sounds are already loaded asynchronously, you can implement a callback using Javaobject when the load is complete, There is an example in this thread: https://www.b4x.com/android/forum/threads/multitrigger-soundpool-example.42038/ How are you loading the sounds? Is there a delay in Debug or release mode?
vfafou Well-Known Member Licensed User Longtime User Mar 30, 2017 #3 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
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!
stevel05 Expert Licensed User Longtime User Mar 30, 2017 #4 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
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.
vfafou Well-Known Member Licensed User Longtime User Mar 30, 2017 #5 stevel05 said: 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. Click to expand... OK, my code is similar to: Code: 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
stevel05 said: 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. Click to expand... OK, my code is similar to: Code: 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.
Erel B4X founder Staff member Licensed User Longtime User Mar 30, 2017 #6 Maybe load the files when they are first needed: Code: Sub GetAudioId(Name As String) As Int If SMap.ContainsKey(Name) = False Then Smap.Put(Name, SndPool.Load(...)) Return Smap.Get(Name) End Sub Upvote 0
Maybe load the files when they are first needed: Code: Sub GetAudioId(Name As String) As Int If SMap.ContainsKey(Name) = False Then Smap.Put(Name, SndPool.Load(...)) Return Smap.Get(Name) End Sub
vfafou Well-Known Member Licensed User Longtime User Mar 30, 2017 #7 Erel said: Maybe load the files when they are first needed: Code: Sub GetAudioId(Name As String) As Int If SMap.ContainsKey(Name) = False Then Smap.Put(Name, SndPool.Load(...)) Return Smap.Get(Name) End Sub Click to expand... Hi, Erel! Thank you for your brain-unstucking instructions! You help is brilliantly precious! Upvote 0
Erel said: Maybe load the files when they are first needed: Code: Sub GetAudioId(Name As String) As Int If SMap.ContainsKey(Name) = False Then Smap.Put(Name, SndPool.Load(...)) Return Smap.Get(Name) End Sub Click to expand... Hi, Erel! Thank you for your brain-unstucking instructions! You help is brilliantly precious!
vfafou Well-Known Member Licensed User Longtime User Mar 30, 2017 #8 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
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!
stevel05 Expert Licensed User Longtime User Mar 30, 2017 #9 Check the link in post #2, it provides a method to get a callback when the file is loaded. Upvote 0
vfafou Well-Known Member Licensed User Longtime User Mar 30, 2017 #10 Thank you again stevel05! I've already done it! It's working like a charm! Upvote 0