World > Music#

class miniworlds.worlds.manager.music_manager.MusicManager(app)[source]#

Public Methods:

__init__(app)

pause()

Pauses the currently playing music.

is_playing()

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.

get_volume()

Gets the current playback volume.

toggle_pause()

Toggles the pause state of the music.


get_path()[source]#

Returns the path of the currently loaded music file.

Return type:

str

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:

float

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:

bool

Returns:

True if music is playing, False otherwise.

Examples

>>> if world.music.is_playing():
...     print("Music is playing.")
pause()[source]#

Pauses the currently playing music.

Return type:

None

Examples

>>> world.music.pause()
play(path=None, loop=-1)[source]#

Plays a music file from the given path.

Return type:

None

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:

None

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)
stop()[source]#

Stops the currently playing music.

Return type:

None

Examples

>>> world.music.stop()
toggle_pause()[source]#

Toggles the pause state of the music. Pauses if playing, resumes if paused.

Return type:

None

Note

This assumes that the internal music manager has a resume() method.

Examples

>>> world.music.toggle_pause()