Android Question Soundpool sound not playing on first run...

JohnC

Expert
Licensed User
Longtime User
I am using the Audio Lib 1.63. And I am using Soundpool to play a quick "beep" file.

This is my code:

B4X:
pid = VoiceIt.SP.Play(StartBeep, 1, 1, 10, 0,0)

But, intermittently, the first time I try to play a file after the app starts, it wont play, other times it will. And all subsequent attempts to play the same sound in the same app session work 100%. So it just sometimes has issues on the first attempt to play something.

So, I added some retry and diag code:

B4X:
SP.Initialize(2)
StartBeep = VoiceIt.SP.Load(File.DirAssets,"beep.ogg")
StopBeeps = VoiceIt.SP.Load(File.DirAssets,"2-beeps.ogg")

Dim i, pid As Int
For i = 1 To 1000
    pid = VoiceIt.SP.Play(StartBeep, 1, 1, 10, 0,0)
    If (pid > 0) Then
        ToastMessageShow("PlayBeep: Pid=" & pid,True)
        Exit
    Else
        Log("PlayBeep: Pid=0, i=" & i) 
    End If
Next

And when it failed (didn't hear the sound), it said the pid was "1", so it appears there wasn't an error.

Does anyone have an idea why it *intermittently* wont play, but doesn't report an error?
 

JohnC

Expert
Licensed User
Longtime User
I am assuming the return value of SP.Load is a successful one because I only execute the Sp.Load in the "FirstTime = True" section of activity_create, but I can then use the same return value to play the file a second and third time with the same value, and it will always play the sound.

It's just that it seems like it thinks it played the sound OK because the first time I play it, the SP.Play call returns a "1", then the second time I play it, it returns a "3" and then "5" and "7" and so on.

Maybe it has to do with the priority parameter, meaning that the first time I try to play it, my priority value of 10 is too low for some reason/something else playing on the phone (even though I don't hear anything else playing). But, I don't know the acceptable range for this parameter to know what a "high" priority value should be in order to try to test a higher value.
 
Upvote 0

JohnC

Expert
Licensed User
Longtime User
Thanks I'll try that - I'm surprised that SP.PLAY doesn't return an error if it's not ready.
 
Upvote 0

JohnC

Expert
Licensed User
Longtime User
Darn, I tried the delay, and still have the intermittent problem, but the SP.Play still returned a pid of "1" as if there wasn't any problem.

Just in case I wasn't clear, the first time I am trying to play the beep is right after the app loads - a lot happens when the app was started, and the last line in the activity_create is to call the sub that sets up the audio recorder and then tries to play this beep file before initiating the AR.Start
 
Upvote 0

JohnC

Expert
Licensed User
Longtime User
It happens on both my two devices.

Since it seems to only happen intermittently right after the app first runs, I'm going to make a 100ms of silence sound file and play it right when the app starts, then play my beep - maybe the blank sound file will wake up Soundpool so it's ready for the real file right after it.
 
Upvote 0
Top