Soundpool inconsistency

jpvniekerk

Active Member
Licensed User
Longtime User
I am trying to a warning sound upon certain conditions using SoundPool.

It reacts inconsistently on one and among several devices. It sometimes plays the sound correctly, sometimes twice, and sometimes not at all. On my Galaxy S2 all three occur - and I could not find any logic behind when each instance occur.

It is in a long program, so I cannot attach it, but the SoundPool parts are as follows:

B4X:
Sub Process_Globals
     .
     .
     Dim SP As SoundPool
     .
     .      
End Sub

Sub Globals
     .
     .
     Dim LoadDingDong As Int
     Dim PlayDingDong As Int
     .
     .
End Sub

Sub Activity_Create(FirstTime As Boolean)
     .
     .
     If FirstTime Then
   .
   .
   SP.Initialize(4)
   LoadDingDong = SP.Load(File.DirAssets,"DingDong.MP3")
   .
   .
     End If
End Sub

Sub CheckConditions
     .
     .
     If Cond1 = True Then
          If Cond2 = True Then
               If Cond3 = True Then
                    PlayDingDong = SP.Play(LoadDingDong,1,1,1,0,1)
                    Result = Msgbox2(message,warning,option1,option2,option3,Null)
                    Select Result
                         .
                         .
               End If
          End If
     End If
End Sub

Can anybody shed some light on this?
Is there a better (more consistent) way to make a warning sound?
Should I use Beeper or MediaPlayer instead?

Thanks for any help
 

Djembefola

Active Member
Licensed User
Longtime User
soundpool with mp3 does not work correctly on some devices.

you can try to use ogg files or short wav files with soundpool.

Stevel05's audiotrack library works fine with short wav files, played back in static mode.
 
Upvote 0

jpvniekerk

Active Member
Licensed User
Longtime User
Thanks,

Changed the file to OGG - still get a double play on the Galaxy S2 Have not had a chance to test thoroughly to see if it will play every time!
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…