World > Music#
- class miniworlds.worlds.manager.music_manager.MusicManager(app)[source]#
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()[source]#
Returns the path of the currently loaded music file.
- Return type:
- Returns:
Path to the current music file.
Examples
>>> current_path = world.music.get_path() >>> print(current_path)
- get_volume()[source]#
Gets the current playback volume.
- Return type:
- Returns:
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()[source]#
Checks if music is currently playing (not paused).
- Return type:
- Returns:
True if music is playing, False otherwise.
Examples
>>> if world.music.is_playing(): ... print("Music is playing.")
- play(path=None, loop=-1)[source]#
Plays a music file from the given path.
- Return type:
- Parameters:
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)[source]#
Sets the playback volume.
- Return type:
- Parameters:
volume – Volume level from 0.0 (silent) to 100.0 (maximum).
- Raises:
ValueError – If volume is outside the 0-100 range.
Examples
>>> world.music.set_volume(80)