Basics

Guides

API Reference

Menu

Basics

Guides

API Reference

class: AudioPlayer

[20:7] extends: EngineService

Wraps FXGL's AudioPlayer (com.almasb.fxgl.audio.AudioPlayer), the engine service that tracks active Music and Sound instances, manages global volume, and pauses/resumes music when the window minimizes. Obtain at runtime via fxgl.getAudioPlayer(); the wrapper provides the play/pause/stop/loop API plus the bulk operations (stopAllSounds, stopAllMusic, stopAllSoundsAndMusic). Sound / Music wrappers from the existing aus/fxgl/Sound.aus and Music.aus pair with this service.

Methods

  • AudioPlayer (Ajo = null)

    Creates an AudioPlayer wrapper. Empty by default; the (Ajo) form wraps the running engine's instance.

    • @p Ajo is an optional AussomJavaObject around an AudioPlayer.
  • adopt (object Ajo)

    Wraps an existing AudioPlayer AussomJavaObject.

    • @p Ajo is an AussomJavaObject around an AudioPlayer.
    • @r A new wrapper.
  • playSound (object SoundObj)

    Plays the given Sound (one-shot effect).

    • @p SoundObj is a Sound wrapper.
    • @r this object
  • stopSound (object SoundObj)

    Stops the given Sound mid-playback.

    • @p SoundObj is a Sound wrapper.
    • @r this object
  • stopAllSounds ()

    Stops every currently-playing sound.

    • @r this object
  • playMusic (object MusicObj)

    Plays the given Music track (single play).

    • @p MusicObj is a Music wrapper.
    • @r this object
  • loopMusic (object MusicObj)

    Loops the given Music track indefinitely.

    • @p MusicObj is a Music wrapper.
    • @r this object
  • pauseMusic (object MusicObj)

    Pauses the given Music track. Resumes on resumeMusic.

    • @p MusicObj is a Music wrapper.
    • @r this object
  • resumeMusic (object MusicObj)

    Resumes a paused Music track.

    • @p MusicObj is a Music wrapper.
    • @r this object
  • stopMusic (object MusicObj)

    Stops the given Music track mid-playback.

    • @p MusicObj is a Music wrapper.
    • @r this object
  • pauseAllMusic ()

    Pauses every currently-playing Music track.

    • @r this object
  • resumeAllMusic ()

    Resumes every paused Music track.

    • @r this object
  • playAllMusic ()

    Plays every active Music track.

    • @r this object
  • stopAllMusic ()

    Stops every active Music track.

    • @r this object
  • stopAllSoundsAndMusic ()

    Stops every active Sound and Music track.

    • @r this object
  • loadAudio (string TypeName, string UrlString, bool IsMobile = false)

    Loads an Audio object from the given URL string and AudioType. Use for loading audio assets outside the normal AssetLoader path.

    • @p TypeName is the AudioType name ("MUSIC" or "SOUND").
    • @p UrlString is the URL to load from.
    • @p IsMobile is true to use the mobile-optimized loader.
    • @r An AussomJavaObject around the loaded Audio.