walterf25 Expert Licensed User Longtime User Mar 22, 2013 #1 Hello All, i have this code on an activity, but the sound doesn't play when the activity is started. Code: Copy Activity.LoadLayout("Green1") sp.Initialize(1) sound = sp.Load(File.DirAssets, "ding.mp3") sp.Play(sound, 1, 1, 1, 0, 1) but if i put the sp.play(sound, 1, 1, 1, 0, 1) Click to expand... inside a Sub Button1_click then it plays when i click the button, i'm confused why won't the sound play as soon as the activity starts? Any thoughts? Thanks Walter
Hello All, i have this code on an activity, but the sound doesn't play when the activity is started. Code: Copy Activity.LoadLayout("Green1") sp.Initialize(1) sound = sp.Load(File.DirAssets, "ding.mp3") sp.Play(sound, 1, 1, 1, 0, 1) but if i put the sp.play(sound, 1, 1, 1, 0, 1) Click to expand... inside a Sub Button1_click then it plays when i click the button, i'm confused why won't the sound play as soon as the activity starts? Any thoughts? Thanks Walter
Erel B4X founder Staff member Licensed User Longtime User Mar 22, 2013 #2 The native SoundPool has some issues. Try to change the volume and also try to convert your file to OGG instead of mp3. Upvote 0
The native SoundPool has some issues. Try to change the volume and also try to convert your file to OGG instead of mp3.
stevel05 Expert Licensed User Longtime User Mar 22, 2013 #3 Soundpool is not like Media Player in that when you issue the Load command, it decompresses the whole sound into memory before it can play. There is a related thread here with a couple of possible solutions, although if you choose the second one, I would use a timer rather than a loop to test if it's loaded. If this introduces too much delay, I would suggest using media player for this purpose. Last edited: Mar 22, 2013 Upvote 0
Soundpool is not like Media Player in that when you issue the Load command, it decompresses the whole sound into memory before it can play. There is a related thread here with a couple of possible solutions, although if you choose the second one, I would use a timer rather than a loop to test if it's loaded. If this introduces too much delay, I would suggest using media player for this purpose.
Informatix Expert Licensed User Longtime User Mar 22, 2013 #4 walterf25 said: Hello All, i have this code on an activity, but the sound doesn't play when the activity is started. Code: Copy Activity.LoadLayout("Green1") sp.Initialize(1) sound = sp.Load(File.DirAssets, "ding.mp3") sp.Play(sound, 1, 1, 1, 0, 1) but if i put the inside a Sub Button1_click then it plays when i click the button, i'm confused why won't the sound play as soon as the activity starts? Any thoughts? Thanks Walter Click to expand... Don't put sp.Play in Activity_Create. It's not the place for it. Move it in Activity_Resume and that should work. Upvote 0
walterf25 said: Hello All, i have this code on an activity, but the sound doesn't play when the activity is started. Code: Copy Activity.LoadLayout("Green1") sp.Initialize(1) sound = sp.Load(File.DirAssets, "ding.mp3") sp.Play(sound, 1, 1, 1, 0, 1) but if i put the inside a Sub Button1_click then it plays when i click the button, i'm confused why won't the sound play as soon as the activity starts? Any thoughts? Thanks Walter Click to expand... Don't put sp.Play in Activity_Create. It's not the place for it. Move it in Activity_Resume and that should work.
walterf25 Expert Licensed User Longtime User Mar 22, 2013 #5 soundpool issue Hi all, thanks for all the suggestions, @informatix, i actually tried putting the sp.play Click to expand... command in the Activity_Resume but in did not work either. I finally got it working this way. I had to initialize the sp variable in the Sub_Globals and load the .mp3 files from the main activity, then when i call them from the other two activities like this called from Green1 activity Code: Copy Main.sp.Play(Main.loadid, 1, 1, 1, 0, 1) and this called from Red1 Activity Code: Copy Main.sp1.Play(Main.loadid1, 1, 1, 1, 0, 1) and this workd good, i'm not sure why but it works, :sign0060: Thanks all for your help! Upvote 0
soundpool issue Hi all, thanks for all the suggestions, @informatix, i actually tried putting the sp.play Click to expand... command in the Activity_Resume but in did not work either. I finally got it working this way. I had to initialize the sp variable in the Sub_Globals and load the .mp3 files from the main activity, then when i call them from the other two activities like this called from Green1 activity Code: Copy Main.sp.Play(Main.loadid, 1, 1, 1, 0, 1) and this called from Red1 Activity Code: Copy Main.sp1.Play(Main.loadid1, 1, 1, 1, 0, 1) and this workd good, i'm not sure why but it works, :sign0060: Thanks all for your help!
Informatix Expert Licensed User Longtime User Mar 24, 2013 #6 It's strange because I used SoundPool in many cases in my recent app and never had a problem like this. But it's fine if that works that way. Upvote 0
It's strange because I used SoundPool in many cases in my recent app and never had a problem like this. But it's fine if that works that way.