def set_audio_file(self, new_track, s=None): """ Set new audio file :param new_track: True - new file "param s" button state """ state = State() state.folder = PODCASTS_FOLDER if s.status == STATUS_LOADED: state.url = s.file_name state.original_url = s.url else: state.url = s.url self.config[PLAYER_SETTINGS][PAUSE] = False state.mute = self.config[PLAYER_SETTINGS][MUTE] state.pause = self.config[PLAYER_SETTINGS][PAUSE] state.file_type = FILE_AUDIO state.dont_notify = True state.source = FILE_AUDIO state.playback_mode = FILE_AUDIO state.status = s.status if hasattr(s, "file_name"): state.file_name = s.file_name source = None if s: source = getattr(s, "source", None) if new_track: tt = 0.0 else: tt = self.config[PODCASTS][PODCAST_EPISODE_TIME] if (isinstance(tt, str) and len(tt) != 0) or ( isinstance(tt, float) or (source and source == RESUME)) or isinstance(tt, int): state.track_time = tt self.time_control.slider.set_position(0) if self.file_button and self.file_button.components[ 1] and self.file_button.components[1].content: state.icon_base = self.file_button.components[1].content if s: if self.config[VOLUME_CONTROL][ VOLUME_CONTROL_TYPE] == VOLUME_CONTROL_TYPE_PLAYER: state.volume = s.volume else: state.volume = None if getattr(s, "full_screen_image", None) != None: state.full_screen_image = s.full_screen_image self.notify_play_listeners(state)
def handle_metadata(self, state=None): """ Handle metadata UI callback :param state: metadata object """ if not state: return if "picture" in state.keys(): img = ("current_shairport_image", state["picture"]) self.set_file_button(img) self.file_button.clean_draw_update() state = State() state.icon_base = img state.full_screen_image = img self.change_screensaver_image(state) elif "current_title" in state.keys(): title = state["current_title"] self.screen_title.set_text(title) elif "volume" in state.keys(): volume = state["volume"] self.volume.set_position(volume) self.volume.update_position() self.volume.notify_slide_listeners() elif "stream" in state.keys(): type = state["stream"] if type == "end": self.play_button.draw_state(1) elif type == "begin": self.play_button.draw_state(0) elif "Time" in state.keys() and "seek_time" in state.keys(): state["state"] = "running" if self.visible: if self.update_web_observer: self.update_web_observer()
def set_audio_file(self, new_track, s=None): """ Set new audio file :param new_track: True - new audio file "param s" button state object """ state = State() state.playback_mode = FILE_AUDIO self.current_folder = s.folder state.folder = self.current_folder state.file_name = s.file_name state.url = s.url if state.folder[-1] == os.sep: state.folder = state.folder[:-1] state.full_screen_image = self.set_audio_file_image( state.url.replace('\"', ""), state.folder) self.config[PLAYER_SETTINGS][PAUSE] = False state.mute = self.config[PLAYER_SETTINGS][MUTE] state.pause = self.config[PLAYER_SETTINGS][PAUSE] self.play_button.draw_default_state(None) state.file_type = FILE_AUDIO state.dont_notify = True folder = self.config[COLLECTION_PLAYBACK][COLLECTION_FOLDER] self.audio_files = self.util.get_audio_files_in_folder(folder, False) source = None if s: source = getattr(s, "source", None) tt = 0.0 if new_track and hasattr(s, "source") and s.source != INIT: tt = 0.0 else: tt = self.config[COLLECTION_PLAYBACK][COLLECTION_TRACK_TIME] if (isinstance(tt, str) and len(tt) != 0) or ( isinstance(tt, float) or (source and source == RESUME)) or isinstance(tt, int): state.track_time = tt if self.show_time_control: self.time_control.slider.set_position(0) if self.file_button and self.file_button.components[ 1] and self.file_button.components[1].content: state.icon_base = self.file_button.components[1].content if self.file_button and hasattr(s, "index"): self.file_button.state.index = s.index else: self.file_button.state.index = 0 if s: if self.config[VOLUME_CONTROL][ VOLUME_CONTROL_TYPE] == VOLUME_CONTROL_TYPE_PLAYER: state.volume = s.volume else: state.volume = None if getattr(s, "full_screen_image", None) != None: state.full_screen_image = s.full_screen_image song_name = self.get_song_name(s) if song_name != None: state.album = song_name self.notify_play_listeners(state)
def set_audio_file(self, new_track, s=None): """ Set new audio file :param new_track: True - new audio file "param s" button state object """ state = State() if s: state.playback_mode = getattr(s, "playback_mode", FILE_AUDIO) state.playlist_track_number = getattr(s, "playlist_track_number", None) if self.config[CURRENT][MODE] == CD_PLAYER and getattr( s, "source", None) != INIT: image_base = getattr(s, "image_base", None) if image_base != None: state.image_base = image_base else: m = self.config[FILE_PLAYBACK][CURRENT_FILE_PLAYBACK_MODE] if m: state.playback_mode = m else: state.playback_mode = FILE_AUDIO if self.config[CURRENT][MODE] == AUDIO_FILES: self.current_folder = self.config[FILE_PLAYBACK][CURRENT_FOLDER] if not self.current_folder: return state.folder = self.current_folder state.file_name = self.config[FILE_PLAYBACK][CURRENT_FILE] if state.folder[-1] == os.sep: state.folder = state.folder[:-1] if os.sep in state.file_name: state.url = "\"" + state.file_name + "\"" else: state.url = "\"" + state.folder + os.sep + state.file_name + "\"" state.music_folder = self.config[AUDIO][MUSIC_FOLDER] elif self.config[CURRENT][MODE] == CD_PLAYER: state.file_name = s.file_name state.url = getattr(s, "url", s.file_name) parts = s.file_name.split() self.config[CD_PLAYBACK][CD_DRIVE_NAME] = parts[0][len("cdda:///" ):] id = self.cdutil.get_cd_drive_id_by_name( self.config[CD_PLAYBACK][CD_DRIVE_NAME]) self.config[CD_PLAYBACK][CD_DRIVE_ID] = int(id) self.config[CD_PLAYBACK][CD_TRACK] = int(parts[1].split("=")[1]) self.config[PLAYER_SETTINGS][PAUSE] = False state.mute = self.config[PLAYER_SETTINGS][MUTE] state.pause = self.config[PLAYER_SETTINGS][PAUSE] state.file_type = FILE_AUDIO state.dont_notify = True state.source = FILE_AUDIO if self.config[FILE_PLAYBACK][ CURRENT_FILE_PLAYBACK_MODE] == FILE_AUDIO or self.config[ CURRENT][MODE] == CD_PLAYER: self.audio_files = self.get_audio_files() elif self.config[FILE_PLAYBACK][ CURRENT_FILE_PLAYBACK_MODE] == FILE_PLAYLIST: state.file_name = self.config[FILE_PLAYBACK][CURRENT_FILE_PLAYLIST] self.load_playlist(state) state.file_name = self.config[FILE_PLAYBACK][CURRENT_FILE] self.audio_files = self.get_audio_files_from_playlist() state.playback_mode = FILE_PLAYLIST n = getattr(s, "file_name", None) if n: state.file_name = n try: state.playlist_track_number = int(state.file_name) - 1 except: state.playlist_track_number = self.get_current_track_index( state) source = None if s: source = getattr(s, "source", None) if new_track: tt = 0.0 else: if self.config[CURRENT][MODE] == CD_PLAYER: tt = self.config[CD_PLAYBACK][CD_TRACK_TIME] else: tt = self.config[FILE_PLAYBACK][CURRENT_TRACK_TIME] if (isinstance(tt, str) and len(tt) != 0) or ( isinstance(tt, float) or (source and source == RESUME)) or isinstance(tt, int): state.track_time = tt self.time_control.slider.set_position(0) if self.file_button and self.file_button.components[ 1] and self.file_button.components[1].content: state.icon_base = self.file_button.components[1].content if s and s.volume: state.volume = s.volume if self.config[CURRENT][MODE] == CD_PLAYER and s and getattr( s, "source", None) == INIT: try: self.cd_album = self.util.cd_titles[self.config[CD_PLAYBACK] [CD_DRIVE_NAME]] self.set_cd_album_art_image() state.image_base = self.file_button.components[1].content except: self.cd_album = None if getattr(s, "full_screen_image", None) != None: state.full_screen_image = s.full_screen_image song_name = self.get_song_name(s) if song_name != None: state.album = song_name self.notify_play_listeners(state)