def on_play(self, entry: Any) -> None: entry_type = get_soundtrack_entry_type(entry) name = get_soundtrack_entry_name(entry) assert name is not None if entry_type == 'musicFile': self._want_to_play = self._actually_playing = True _ba.music_player_play(name) elif entry_type == 'musicFolder': # Launch a thread to scan this folder and give us a random # valid file within. self._want_to_play = True self._actually_playing = False self._PickFolderSongThread(name, self._on_play_folder_cb).start()
def _on_play_folder_cb(self, result: Union[str, List[str]], error: Optional[str] = None) -> None: from ba import _lang if error is not None: rstr = (_lang.Lstr( resource='internal.errorPlayingMusicText').evaluate()) if isinstance(result, str): err_str = (rstr.replace('${MUSIC}', os.path.basename(result)) + '; ' + str(error)) else: err_str = (rstr.replace('${MUSIC}', '<multiple>') + '; ' + str(error)) _ba.screenmessage(err_str, color=(1, 0, 0)) return # There's a chance a stop could have been issued before our thread # returned. If that's the case, don't play. if not self._want_to_play: print('_on_play_folder_cb called with _want_to_play False') else: self._actually_playing = True _ba.music_player_play(result)