Play sound in tick

Shay

Well-Known Member
Licensed User
Longtime User
starnge problem
I build timer
when it reach 10 min it should play sound
it is playing sound, but the timer is "freeze" till 11:00



Sub Time3_Tick

secs2=secs2+10 ' ********* make clock run faster

If secs2 < 10 Then
min_main=0
secs_main=secs2
label_Main_clock.Text = min_main & "0:0" & secs_main
Else
If secs2 < 60 Then
secs_main=secs2
min_main=0
label_Main_clock.Text = min_main & "0:" & secs_main
End If
End If

If secs2 >59 Then
min_main = secs2 / 60
secs_main = secs2 - (60 * min_main)
If secs_main < 10 AND min_main < 10 Then
label_Main_clock.Text = "0" & min_main & ":0" & secs_main
Else
If secs_main > 9 AND min_main < 10 Then
label_Main_clock.Text = "0" & min_main & ":" & secs_main
Else
If secs_main > 9 AND min_main > 10 Then
label_Main_clock.Text = min_main & ":" & secs_main
Else
If secs_main < 10 AND min_main > 10 Then
label_Main_clock.Text = min_main & ":0" & secs_main
End If
End If
End If
End If
End If

If (secs2=600) Then
SP.Play(LoadId2, 1, 1, 1, 0, 1)
End If

End Sub
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
You can simplify your code with a Sub like this one:
B4X:
Sub Activity_Create(FirstTime As Boolean)
    Log(ConvertSeconds(0))
    Log(ConvertSeconds(123))
    Log(ConvertSeconds(10))
    Log(ConvertSeconds(60))
    Log(ConvertSeconds(600))
End Sub

Sub ConvertSeconds (Seconds As Int) As String
    Dim minutes As Int
    minutes = Floor(Seconds / 60)
    Return NumberFormat(minutes, 2, 0) & ":" & NumberFormat(Seconds Mod 60, 2, 0)
End Sub
 
Upvote 0
Top