Android Question SoundPool Error - maximum Number of Streams?

Quillok

Member
Licensed User
Longtime User
Hey,

I've got a problem in my app that I can't reproduce so it's a bit difficult.
I'm using SoundPool and set the maximum number of simultanous streams to 15 (which is never reached). But I don't know which is the maximum number that could happen so I set it high. At my device everything works, but on the devices of two friends, there is the problem that at some point (not reproducable) the sound is played but then there starts a loud noise sound. I guess the length of that noise is as long as one of the sounds is playing. As far as I know, they are using Android 6 (I've got an "older" device too with Android 6, but can't get that error).

My question: Is it possible that on older devices the maximum number of soundpool sounds is limited and then it is coming to that error with the noise sound? Maybe because too much sounds are overlapping? I did not using the priority of the sounds, every sound has the same priority, is it possible that that could fix this error?

Is this a known error or did I discovered first? Can I name it? šŸ˜…

*Edit*
I have just noticed that I use PlayIDs more than once, can this be the reason?

B4X:
Sub PlaySound(id As Int)
    If Sound = True Then
        Select id
            Case 0
                PlayAchievemntID = SP.Play(LoadAchievementID,1,1,1,0,1)
            Case 1
                PlayID1 = SP.Play(LoadID1, 1, 1, 1, 0, 1)
            Case 2
                PlayID1 = SP.Play(LoadID2, 1, 1, 1, 0, 1)
            Case 3
                PlayID1 = SP.Play(LoadID3, 1, 1, 1, 0, 1)
            Case 4
                PlayID2 = SP.Play(LoadID4, 1, 1, 1, 0, 1)
            '...'
        End Select
    End if
End Sub
 
Last edited:

Erel

B4X founder
Staff member
Licensed User
Longtime User
SoundPool.Play returns 0 if there was an error. You can simplify your code with:
B4X:
Sub PlaySound(id As Int)
    If Sound = True Then
      If SP.Play(id, 1, 1, 1, 0, 1) = 0 Then Log("Error playing")
    End If
End Sub

About the actual problem:
1. It is possible that some devices, especially older ones, will have problems with playing multiple sounds together.
2. Check the value returned from SP.Load. If I remember correctly it will be 0 if there is any error.
Also worth monitor the unfiltered logs when the problem happens.
 
Upvote 0
Top