B4X:
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Dim sp As SoundPool
Dim BrownNoiseId As Int
End Sub
Sub Globals
Dim tbBrownNoise As ToggleButton
Dim tbWhiteNoise As ToggleButton
End Sub
Sub Activity_Create(FirstTime As Boolean)
If FirstTime Then
sp.Initialize(1)
BrownNoiseId = sp.Load(File.DirAssets, "brown.ogg")
End If
Activity.LoadLayout("main")
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
If UserClosed = True Then
sp.Stop(BrownNoiseId)
End If
End Sub
Sub tbBrownNoise_CheckedChange(Checked As Boolean)
If tbBrownNoise.Checked = True Then
Log("brown noise on")
sp.Play(BrownNoiseId, 1, 1, 1, -1, 1)
Else
Log("brown noise off")
sp.Stop(BrownNoiseId)
End If
End Sub
This sub is not working as expected: Sub tbBrownNoise_CheckedChange(Checked As Boolean)
brown.ogg is a 5 second audio file
The first time i click on the toggle button it starts playing the sound. When I click the toggle button again it doesn't always stop playing the sound. Further turning the toggle button ON or OFF will start or stop the sound sometimes, but not every time. Also, it doesn't seem to matter much if the button is ON or OFF, it will play or stop when it feels like it, no matter if it is ON or OFF.
Any idea why?
I would like to note that the Log() command works properly every time, so that tells me the event is firing as it should, I am just not sure why the sound isn't playing/stopping properly.
Thanks,
Eric H
Last edited: