Android Question SoundPool - Problem not playing short sound

Azhar

Active Member
Licensed User
Hi

I have this problem in that no sound is made.

B4X:
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
    Dim phoneVib As PhoneVibrate
    Dim phone As Phone
    Dim NMTimer As Timer
    Dim sp As SoundPool
    
    .....
    
    
Sub Activity_Create(FirstTime As Boolean)
    'initialise the pong mp3 sound
    sp.Initialize(3)
    
    ......
    
Sub playBeepSound
    Dim LoadId As Int = sp.Load(File.DirAssets, "Pong.mp3")

    Log("Play Beep Sound. LoadID is " & LoadId)
    'LoadID L_Vol(0-1)   R_Vol(0-1)   Priority   Loop(Repeat Cycles)   Rate(0-2)
    
    If sp.Play(LoadId,1,1,1,0,1) = 0 Then
        Log("Error")
    Else
        sp.Play(LoadId,1,1,1,0,1)
    End If
End Sub

In the unfiltered logs, it shows the following:

->Play Beep Sound. LoadID is 1
sample 1 not READY
+++initMMListConfigFile glnitDone 1
found audio mime = audio/mpeg
Don't need create ffmpeg
Treblw IOmx obtained
-> Error

Can anyone shed some light as to why it doesn't work?

Thanks,

Azhar
 

Azhar

Active Member
Licensed User
I have just resolved the issue.
I had to create the loadID as global
Then immediately after the sp.initialize(3) added the sp.load(.....

I'm assuming from the unfiltered log where it says 'sample 1 not READY' that this was the case.
So I pre-loaded the sound file in Activity_Create.

Now it works
 
Upvote 0

stevel05

Expert
Licensed User
The logic here is flawed:
B4X:
    If sp.Play(LoadId,1,1,1,0,1) = 0 Then
        Log("Error")
    Else
        sp.Play(LoadId,1,1,1,0,1)
    End If

As if the sound plays from the call in the first line, it will attempt to play it again, which may be why it is not playing.

Try changing it to
B4X:
    If sp.Play(LoadId,1,1,1,0,1) = 0 Then
        Log("Error")
    Else
        Log("OK")
    End If
 
Upvote 0
Top