Sub tmrForSchedules_Tick
' Loop through all songs.
' We will exit the loop if the time now is within any scheduled song period to play a song.
' If any is found regardless of wether or not the user is listening to a song, these will be
' played.
'-------------------------------------------------------------------------------------------
For intSongNumber = 1 To 3
' Check if the song has a schedule that's ok to test (light bulb is on).
'-----------------------------------------------------------------------
If kvs.Get("Song" & intSongNumber & "ScheduleIsActivated") Then ' The light bulb is on.
' Get the ticks value for the songs starting period.
'----------------------------------------------------
Dim lngScheduleFrom As Long = _
DateTime.DateTimeParse(DateTime.Date(DateTime.Now), _
kvs.Get("Song" & intSongNumber & "ScheduleActiveFrom") & ":00")
' Check if the ending period is set for the next day.
'--------------------------------------------------
If kvs.Get("Song" & intSongNumber & "ScheduleIsOvernight") Then
' Get the ticks value for the ending period for tomorrow.
'--------------------------------------------------------
Dim lngScheduleUntil As Long = _
DateTime.Add(DateTime.DateTimeParse(DateTime.Date(DateTime.Now), _
kvs.Get("Song" & intSongNumber & "ScheduleActiveUntil") & ":00"),0,0,1)
Else
' Get the ticks value for the ending today.
'------------------------------------------
Dim lngScheduleUntil As Long = DateTime.DateTimeParse(DateTime.Date(DateTime.Now), _
kvs.Get("Song" & intSongNumber & "ScheduleActiveUntil") & ":00")
End If
Select intSongNumber
Case 1
' Go here only if a song is not playing for schedule 2 or 3.
'-----------------------------------------------------------
If blnSchedule2IsPlayingSong = False And _
blnSchedule3IsPlayingSong = False Then
' Go here if the time now is inside the schedul period for song 1.
'-----------------------------------------------------------------
If DateTime.Now >= lngScheduleFrom And _
DateTime.Now <= lngScheduleUntil Then
' Go here if the schedule is not running. This ensures the song is only
' played the first time the time now is in the schedule period.
'----------------------------------------------------------------------
If blnSchedule1IsPlayingSong = False Then
blnSchedule1IsPlayingSong = True
blnScheduleIsPlayingSong = True ' Flag used in the Main module.
Main.blnAsongIsPlaying = False ' Toggle to make the song play.
CallSubDelayed(Main, "ImageViewPlayCurrentSong_Click")
Log("Schedule For Song " & intSongNumber & " is running.")
End If
Else
' Go here if the schedule is running. This ensures the song is only
' stopped the first time the time now is outside of the schedule period.
'-----------------------------------------------------------------------
If blnSchedule1IsPlayingSong = True Then
blnSchedule1IsPlayingSong = False
blnScheduleIsPlayingSong = False ' Flag used in the Main module.
Main.blnAsongIsPlaying = True ' Toggle to make the song stop.
CallSubDelayed(Main, "ImageViewPlayCurrentSong_Click")
Log("Schedule For Song " & intSongNumber & " has ended.")
End If
End If
End If
Case 2
' Go here if the time now is inside the schedul period for song 2.
'-----------------------------------------------------------------
If blnSchedule1IsPlayingSong = False And _
blnSchedule3IsPlayingSong = False Then
' Go here only once if the time now is inside the schedul period for song 2.
'---------------------------------------------------------------------------
If DateTime.Now >= lngScheduleFrom And _
DateTime.Now <= lngScheduleUntil Then
' Go here if the schedule is not running. This ensures the song is only
' played the first time the time now is in the schedule period.
'----------------------------------------------------------------------
If blnSchedule2IsPlayingSong = False Then
blnSchedule2IsPlayingSong = True
blnScheduleIsPlayingSong = True ' Flag used in the Main module.
Main.blnAsongIsPlaying = False ' Toggle to make the song play.
CallSubDelayed(Main, "ImageViewPlayCurrentSong_Click")
Log("Schedule For Song " & intSongNumber & " is running.")
End If
Else
' Go here if the schedule is running. This ensures the song is only
' stopped the first time the time now is outside of the schedule period.
'-----------------------------------------------------------------------
If blnSchedule2IsPlayingSong = True Then
blnSchedule2IsPlayingSong = False
blnScheduleIsPlayingSong = False ' Flag used in the Main module.
Main.blnAsongIsPlaying = True ' Toggle to make the song stop.
CallSubDelayed(Main, "ImageViewPlayCurrentSong_Click")
Log("Schedule For Song " & intSongNumber & " has ended.")
End If
End If
End If
Case 3
' Go here if the time now is inside the schedul period for song 3.
'-----------------------------------------------------------------
If blnSchedule1IsPlayingSong = False And _
blnSchedule2IsPlayingSong = False Then
' Go here only once if the time now is inside the schedul period for song 3.
'---------------------------------------------------------------------------
If DateTime.Now >= lngScheduleFrom And _
DateTime.Now <= lngScheduleUntil Then
' Go here if the schedule is not running. This ensures the song is only
' played the first time the time now is in the schedule period.
'----------------------------------------------------------------------
If blnSchedule3IsPlayingSong = False Then
blnSchedule3IsPlayingSong = True
blnScheduleIsPlayingSong = True ' Flag used in the Main module.
Main.blnAsongIsPlaying = False ' Toggle to make the song play.
CallSubDelayed(Main, "ImageViewPlayCurrentSong_Click")
Log("Schedule For Song " & intSongNumber & " is running.")
End If
Else
' Go here if the schedule is running. This ensures the song is only
' stopped the first time the time now is outside of the schedule period.
'-----------------------------------------------------------------------
If blnSchedule3IsPlayingSong = True Then
blnSchedule3IsPlayingSong = False
blnScheduleIsPlayingSong = False ' Flag used in the Main module.
Main.blnAsongIsPlaying = True ' Toggle to make the song stop.
CallSubDelayed(Main, "ImageViewPlayCurrentSong_Click")
Log("Schedule For Song " & intSongNumber & " has ended.")
End If
End If
End If
End Select
Else ' The light bulb is off.
Select intSongNumber
Case 1
' Go here if the schedule is running. This ensures the song is only
' stopped the first time the turns off the light bulb for the schedule.
'----------------------------------------------------------------------
If blnSchedule1IsPlayingSong = True Then
blnSchedule1IsPlayingSong = False
blnScheduleIsPlayingSong = False ' Flag used in the Main module.
Main.blnAsongIsPlaying = True ' Toggle to make the song stop.
CallSubDelayed(Main, "ImageViewPlayCurrentSong_Click")
Log("Schedule For Song " & intSongNumber & " has ended.")
End If
Case 2
' Go here if the schedule is running. This ensures the song is only
' stopped the first time the turns off the light bulb for the schedule.
'----------------------------------------------------------------------
If blnSchedule2IsPlayingSong = True Then
blnSchedule2IsPlayingSong = False
blnScheduleIsPlayingSong = False ' Flag used in the Main module.
Main.blnAsongIsPlaying = True ' Toggle to make the song stop.
CallSubDelayed(Main, "ImageViewPlayCurrentSong_Click")
Log("Schedule For Song " & intSongNumber & " has ended.")
End If
Case 3
' Go here if the schedule is running. This ensures the song is only
' stopped the first time the turns off the light bulb for the schedule.
'----------------------------------------------------------------------
If blnSchedule3IsPlayingSong = True Then
blnSchedule3IsPlayingSong = False
blnScheduleIsPlayingSong = False ' Flag used in the Main module.
Main.blnAsongIsPlaying = True ' Toggle to make the song stop.
CallSubDelayed(Main, "ImageViewPlayCurrentSong_Click")
Log("Schedule For Song " & intSongNumber & " has ended.")
End If
End Select
End If
Next
End Sub