Playing looped sound issue after stopped

tamadon

Active Member
Licensed User
Longtime User
I am having problem replaying a looped sound after stopping it. Log(PlayId1) shows that the value increase from 1, 2, 3, 4... each time I pressed the Start button.

Here's my sample code. I've also attached the sound file.

B4X:
'Activity module
Sub Process_Globals
   Dim SP As SoundPool
   Dim LoadId1, PlayId1 As Int
End Sub

Sub Globals
   Dim Button1 As Button
   Dim Button2 As Button
End Sub

Sub Activity_Create(FirstTime As Boolean)
   If FirstTime Then
      SP.Initialize(1)
      LoadId1 = SP.Load(File.DirAssets, "Clock ticking.ogg")
   End If
   Activity.LoadLayout("1")
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub Button1_Click
   PlayId1 = SP.Play(LoadId1, 1, 1, 1, -1, 1)
   Log(PlayId1)
End Sub

Sub Button2_Click
   SP.Stop(PlayId1)
End Sub

What am I missing here? Thanks for the help.
 

Attachments

  • Clock ticking.zip
    46.1 KB · Views: 181

tamadon

Active Member
Licensed User
Longtime User
I think I figured it out. Using Pause, Resume seems to solved the issue

B4X:
Sub Button1_Click
   If firstPlay = True Then
      PlayId1 = SP.Play(LoadId1, 1, 1, 1, -1, 1)
      Log(PlayId1)
   Else
      SP.Resume(PlayId1)
   End If
   
End Sub

Sub Button2_Click
   SP.Pause(PlayId1)
   firstPlay = False
End Sub
 
Upvote 0
Top