Play background music with play/pause/stop/loop controls. More...
| Import Statement: | import Clayground.Sound |
Music provides an interface for playing longer audio tracks like background music. Supports play, pause, stop, seek, and looping.
Example usage:
import Clayground.Sound
Music {
id: bgMusic
source: "music/theme.mp3"
volume: 0.5
loop: true
}
// In game logic:
onGameStarted: bgMusic.play()
onGamePaused: bgMusic.pause()
onGameOver: bgMusic.stop()
For short sound effects, use Sound instead.
See also Sound.
lazyLoading : bool |
When true, the music is not loaded until load() or play() is called.
On desktop this is a no-op (files load instantly). Effective on WASM where network fetching is involved.
loaded : bool |
True when the music data has been loaded and is ready to play.
loop : bool |
When true, the music loops after reaching the end.
paused : bool |
True when the music is paused.
status : int |
Loading status: 0=Null, 1=Loading, 2=Ready, 3=Error.
volume : real |
Playback volume from 0.0 (silent) to 1.0 (full).
finished() |
Emitted when music playback reaches the end.
Note: The corresponding handler is onFinished.
void load() |
Explicitly load the music data (useful with lazyLoading on WASM).
void seek(int ms) |
Seek to the given position in milliseconds.