World > Music#

API Reference#

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

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

Return the path of the currently loaded music file.

Rückgabetyp:

str

Rückgabe:

Path to the current music file.

Examples

current_path = world.music.get_path()
get_volume()[Quellcode]#

Return the current playback volume.

Rückgabetyp:

float

Rückgabe:

Volume level as a float between 0.0 and 100.0.

Examples

current_volume = world.music.get_volume()
is_playing()[Quellcode]#

Return whether music is currently playing.

Rückgabetyp:

bool

Rückgabe:

True if music is playing.

Examples

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

Pause the currently playing music.

Rückgabetyp:

None

Examples

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

Play a music file.

Rückgabetyp:

None

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

Set the playback volume.

Rückgabetyp:

None

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

Stop the currently playing music.

Rückgabetyp:

None

Examples

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

Toggle the pause state of the music.

Rückgabetyp:

None

Bemerkung

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

Examples

world.music.toggle_pause()