World > Music#

API Reference#

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

Controls background music playback for a world.

Access via world.music.

Examples

world.music.play("assets/theme.mp3")
world.music.set_volume(80)
world.music.pause()
world.music.stop()
get_path()[source]#

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

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

Return whether music is currently playing.

Return type:

bool

Returns:

True if music is playing.

Examples

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

Pause the currently playing music.

Return type:

None

Examples

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

Play a music file.

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

Set 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]#

Stop the currently playing music.

Return type:

None

Examples

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

Toggle the pause state of the music.

Return type:

None

Note

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

Examples

world.music.toggle_pause()