← Back to Docs
  • index.html
  • Clayground
  • Clayground.Sound
  • Music
  • Clayground 2025.2
  • Music QML Type

    Play background music with play/pause/stop/loop controls. More...

    Import Statement: import Clayground.Sound

    Properties

    Signals

    Methods

    Detailed Description

    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.

    Property Documentation

    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 [read-only]

    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 [read-only]

    True when the music is paused.


    status : int [read-only]

    Loading status: 0=Null, 1=Loading, 2=Ready, 3=Error.


    volume : real

    Playback volume from 0.0 (silent) to 1.0 (full).


    Signal Documentation

    finished()

    Emitted when music playback reaches the end.

    Note: The corresponding handler is onFinished.


    Method Documentation

    void load()

    Explicitly load the music data (useful with lazyLoading on WASM).


    void seek(int ms)

    Seek to the given position in milliseconds.