(self)
return not error
Wait until the song is over.
        Returns True when finished without errors, False otherwise.
Wait until the song is over.
        Returns True when finished without errors, False otherwise.
Wait until the song is over . Returns True when finished without errors False otherwise .
def wait_until_song_end(self) -> bool:
        """Wait until the song is over.
        Returns True when finished without errors, False otherwise."""
        # This is the event based approach. Unfortunately too error-prone.
        # If mopidy crashes/restarts for example, no track_playback_ended event is sent
        # playback_ended.wait()
        error = False
        while True:
            with mopidy_command() as allowed:
                if allowed:
                    try:
                        if self.player.playback.get_state() == "stopped":
                            break
                    except (requests.exceptions.ConnectionError, MopidyError):
                        # error during state get, skip until reconnected
                        error = True
            time.sleep(0.1)
            if redis.get("stop_playback_loop"):
                # in order to stop the playback thread, return False, making the main loop restart.
                # it will check this variable again and terminate itself.
                return False
            if redis.get("alarm_requested"):
                redis.set("alarm_requested", False)
                self.play_alarm(interrupt=True)
                # the current song was interrupted and needs to be resumed at the correct position
                # returning False will notify the main loop about this interruption,
                # making it restart the song correctly
                current_song = models.CurrentSong.objects.get()
                # we don't want the song to skip over the time when the alarm was playing
                # thus, we offset the creation date of the current song by the length of the alarm
                # Warning: if this duration does not fit the duration of the actual alarm,
                # Raveberry's internal state gets desynced and weird errors happen
                current_song.created += datetime.timedelta(
                    seconds=musiq.get_alarm_metadata()["duration"]
                )
                current_song.save()

                return False
        return not error
def wait_until_song_end ( self ) -> bool : # This is the event based approach. Unfortunately too error-prone. # If mopidy crashes/restarts for example, no track_playback_ended event is sent # playback_ended.wait() error = False while True : with mopidy_command ( ) as allowed : if allowed : try : if self . player . playback . get_state ( ) == "stopped" : break except ( requests . exceptions . ConnectionError , MopidyError ) : # error during state get, skip until reconnected error = True time . sleep ( 0.1 ) if redis . get ( "stop_playback_loop" ) : # in order to stop the playback thread, return False, making the main loop restart. # it will check this variable again and terminate itself. return False if redis . get ( "alarm_requested" ) : redis . set ( "alarm_requested" , False ) self . play_alarm ( interrupt = True ) # the current song was interrupted and needs to be resumed at the correct position # returning False will notify the main loop about this interruption, # making it restart the song correctly current_song = models . CurrentSong . objects . get ( ) # we don't want the song to skip over the time when the alarm was playing # thus, we offset the creation date of the current song by the length of the alarm # Warning: if this duration does not fit the duration of the actual alarm, # Raveberry's internal state gets desynced and weird errors happen current_song . created += datetime . timedelta ( seconds = musiq . get_alarm_metadata ( ) [ "duration" ] ) current_song . save ( ) return False return not error