Android Question wait for playing sound

omarruben

Active Member
Licensed User
Longtime User
Hi, how I can wait for a certain point of a sound playing?

B4X:
MPlaySound.Initialize2(Null)
MPlaySound.Load(File.DirAssets, "awesomesound.mp3")

MPlaySound.Play
    
    Wait For MPlaySound.Position = 1000 ' -----> this does not work, syntax error
    ' then show animation
 

Brian Dean

Well-Known Member
Licensed User
Longtime User
It depends how precise you need to be, but using a timer works ...
B4X:
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.LoadLayout("MainPage")
    mp.Initialize
    tmr.Initialize("timer", 2000)
End Sub

Private Sub Button1_Click
    mp.Load(File.DirAssets, "sample.mp3")
    mp.Play
    tmr.Enabled = True
End Sub

Private Sub timer_Tick
    xui.MsgboxAsync("Time for the show!", "Hooray")
    tmr.Enabled = False
End Sub
 
Upvote 0

omarruben

Active Member
Licensed User
Longtime User
It depends how precise you need to be, but using a timer works ...
B4X:
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.LoadLayout("MainPage")
    mp.Initialize
    tmr.Initialize("timer", 2000)
End Sub

Private Sub Button1_Click
    mp.Load(File.DirAssets, "sample.mp3")
    mp.Play
    tmr.Enabled = True
End Sub

Private Sub timer_Tick
    xui.MsgboxAsync("Time for the show!", "Hooray")
    tmr.Enabled = False
End Sub

Thank you,
I was thinking to use timers also.... but I am planing to maker a few players, around 15 or more... so I was looking for a much more simple solution
 
Upvote 0
Top