Skip to content

Commit

Permalink
Merge pull request #10 from dtseiler/detect_song_end
Browse files Browse the repository at this point in the history
Send STOP signal when player or list finishes
  • Loading branch information
dtseiler authored Aug 21, 2023
2 parents 387a38a + 0b098a3 commit ec438a7
Showing 1 changed file with 22 additions and 8 deletions.
30 changes: 22 additions & 8 deletions hockeybox.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,17 +108,10 @@
# Define our VLC object
instance = vlc.Instance()
player = instance.media_player_new()
player_events = player.event_manager()
list_player = instance.media_list_player_new()
list_events = list_player.event_manager()

def intermission_item_played(event):
global intermission_num_played
intermission_num_played += 1
print("Items Played: %d" % intermission_num_played)
#sleep(1)

list_events.event_attach(vlc.EventType.MediaListPlayerNextItemSet, intermission_item_played)


#
# Function Definitions
Expand Down Expand Up @@ -344,6 +337,27 @@ def stop_playback(channel):
GPIO.add_event_detect(INPUT_BTW, GPIO.RISING, callback=play_btw, bouncetime=1000)
GPIO.add_event_detect(INPUT_STOP, GPIO.RISING, callback=stop_playback, bouncetime=1000)

#
# Event Handlers
#

# Sends the STOP signal when a song has finished playing to completion
def song_finished(event):
print("Song finished, stopping playback")
stop_playback(INPUT_STOP)

# Advances to the next song for intermission lists
def intermission_item_played(event):
global intermission_num_played
intermission_num_played += 1
print("Items Played: %d" % intermission_num_played)
#sleep(1)

player_events.event_attach(vlc.EventType.MediaPlayerEndReached, song_finished)
list_events.event_attach(vlc.EventType.MediaListPlayerPlayed, song_finished)
list_events.event_attach(vlc.EventType.MediaListPlayerNextItemSet, intermission_item_played)


# Flicker the lights
print("Light 'em up.")
for output in outputs:
Expand Down

0 comments on commit ec438a7

Please sign in to comment.