def __change_state(self, new_state): """ Internal function to move to a new state. If new_state is different to the current state, set self.state to new_state and perform any state initialisation for the new state. """ if self.state == new_state: # No change in state nothing todo! return logger.debug('Changing state from %s to %s', self.state, new_state) old_state = self.state self.state = new_state self.current_event_map = self.event_maps[new_state] # State Initialisation code if self.state == State.IDLE: self.state_dialog.hide() rc.remove_app(self) rc.post_event(PLAY_END) self.backend.set_events_enabled(False) elif self.state == State.TUNING: # Display the current state on the OSD self.__draw_state_screen() elif self.state == State.BUFFERING: self.wait_for_data_count = WAIT_FOR_DATA_COUNT # Display the current state on the OSD self.__draw_state_screen() elif self.state == State.PLAYING: # Display the current state on the OSD self.__draw_state_screen() self.player.start((self.backend.get_server_address(), config.LIVE_PAUSE2_PORT)) dialog.enable_overlay_display(self.player.get_display()) self.osd = display.get_osd()
def stop(self): """ Stop playback and go into idle. """ logger.debug('Stopping play back.') display.get_osd().hide() dialog.disable_overlay_display() self.player.stop() self.stop_time = time.time() self.backend.set_events_enabled(False) self.__change_state(State.IDLE) self.disable_buffering_timer.start(config.LIVE_PAUSE2_BUFFER_TIMEOUT) return True