World > Music#
- class miniworlds.worlds.manager.music_manager.MusicManager(app)[Quellcode]#
Public Methods:
__init__
(app)pause
()Pauses the currently playing music.
Checks if music is currently playing (not paused).
get_path
()Returns the path of the currently loaded music file.
play
([path, loop])Plays a music file from the given path.
stop
()Stops the currently playing music.
set_volume
(volume)Sets the playback volume.
Gets the current playback volume.
Toggles the pause state of the music.
- get_path()[Quellcode]#
Returns the path of the currently loaded music file.
- Rückgabetyp:
- Rückgabe:
Path to the current music file.
Examples
>>> current_path = world.music.get_path() >>> print(current_path)
- get_volume()[Quellcode]#
Gets the current playback volume.
- Rückgabetyp:
- Rückgabe:
Volume level as a float between 0.0 and 100.0.
Examples
>>> current_volume = world.music.get_volume() >>> print(f"Volume: {current_volume}")
- is_playing()[Quellcode]#
Checks if music is currently playing (not paused).
- Rückgabetyp:
- Rückgabe:
True if music is playing, False otherwise.
Examples
>>> if world.music.is_playing(): ... print("Music is playing.")
- pause()[Quellcode]#
Pauses the currently playing music.
- Rückgabetyp:
Examples
>>> world.music.pause()
- play(path=None, loop=-1)[Quellcode]#
Plays a music file from the given path.
- Rückgabetyp:
- Parameter:
path – Path to the music file. If None, replays the last used music.
loop – Number of times to repeat the music. Use -1 for infinite looping.
Examples
>>> world.music.play("assets/music/theme.mp3") >>> world.music.play("assets/music/loop.wav", loop=2) >>> world.music.play() # Replays last loaded music
- set_volume(volume)[Quellcode]#
Sets the playback volume.
- Rückgabetyp:
- Parameter:
volume – Volume level from 0.0 (silent) to 100.0 (maximum).
- Verursacht:
ValueError – If volume is outside the 0-100 range.
Examples
>>> world.music.set_volume(80)
- stop()[Quellcode]#
Stops the currently playing music.
- Rückgabetyp:
Examples
>>> world.music.stop()
- toggle_pause()[Quellcode]#
Toggles the pause state of the music. Pauses if playing, resumes if paused.
- Rückgabetyp:
Bemerkung
This assumes that the internal music manager has a resume() method.
Examples
>>> world.music.toggle_pause()