def do_play_music(self, musictype: Union[MusicType, str, None], continuous: bool = False, mode: MusicPlayMode = MusicPlayMode.REGULAR, testsoundtrack: dict[str, Any] = None) -> None: """Plays the requested music type/mode. For most cases, setmusic() is the proper call to use, which itself calls this. Certain cases, however, such as soundtrack testing, may require calling this directly. """ # We can be passed a MusicType or the string value corresponding # to one. if musictype is not None: try: musictype = MusicType(musictype) except ValueError: print(f"Invalid music type: '{musictype}'") musictype = None with _ba.Context('ui'): # If they don't want to restart music and we're already # playing what's requested, we're done. if continuous and self.music_types[mode] is musictype: return self.music_types[mode] = musictype # If the OS tells us there's currently music playing, # all our operations default to playing nothing. if _ba.is_os_playing_music(): musictype = None # If we're not in the mode this music is being set for, # don't actually change what's playing. if mode != self._music_mode: return # Some platforms have a special music-player for things like iTunes # soundtracks, mp3s, etc. if this is the case, attempt to grab an # entry for this music-type, and if we have one, have the # music-player play it. If not, we'll play game music ourself. if musictype is not None and self._music_player_type is not None: if testsoundtrack is not None: soundtrack = testsoundtrack else: soundtrack = self._get_user_soundtrack() entry = soundtrack.get(musictype.value) else: entry = None # Go through music-player. if entry is not None: self._play_music_player_music(entry) # Handle via internal music. else: self._play_internal_music(musictype)
def on_app_resume(self) -> None: """Should be run when the app resumes from a suspended state.""" if _ba.is_os_playing_music(): self.do_play_music(None)
def handle_app_resume() -> None: """Should be run when the app resumes from a suspended state.""" if _ba.is_os_playing_music(): do_play_music(None)