Android Question soundpool not work in android 8

Angi Ili

New Member
Licensed User
Longtime User
<code>
Dim sp As SoundPool
Dim sir,erra As Int
sp.Initialize(1)
sir=sp.Load(File.DirDefaultExternal,"Siren.mp3")
erra=sp.Play(sir,1,1,1,0,1)
Log(erra)
</code>
 

Angi Ili

New Member
Licensed User
Longtime User
thanks Erel for fast reply!
But, I changed -File.DirDefaultExternal- to -File.dirAssets - and again nothing is playing. The erra return 0.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
1. Don't remove the starter service.
2. Don't initialize SoundPool multiple times.
3. Don't initialize SoundPool when the activity is created. Only when FirstTime = True.

This code works fine here:
B4X:
Sub Process_Globals
    Private sp As SoundPool
    Private SirenIndex As Int
End Sub

Sub Globals
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("1")
    If FirstTime Then
        sp.Initialize(2)
        SirenIndex = sp.Load(File.DirAssets,"Siren0.mp3")
    End If
End Sub

Sub Activity_Touch (Action As Int, X As Float, Y As Float)
    If Action = Activity.ACTION_DOWN Then
        sp.Play(SirenIndex, 1, 1, 1, 0, 1)
    End If
End Sub
 
Upvote 0
Top