Basics

Guides

API Reference

Menu

Basics

Guides

API Reference

class: MediaPlayer

[15:7] extends: FxObj

Wraps JavaFX MediaPlayer, which controls playback of a Media resource, including play, pause, stop, seek, volume, and loop control. Construct it with a Media object, then call play() to start playback. Volume is set as a value between 0.0 (silent) and 1.0 (full). setCycleCount() controls how many times the media repeats, and setOnEndOfMedia() registers a callback that fires when playback reaches the end.

Methods

  • MediaPlayer (object MediaObj)

    Creates a new MediaPlayer that will play the given Media resource.

    • @p MediaObj is a Media object representing the audio or video resource.
    • @r this object
  • play ()

    Starts or resumes playback of the media.

    • @r this object for chaining
  • pause ()

    Pauses playback at the current position.

    • @r this object for chaining
  • stop ()

    Stops playback and resets the position to the beginning.

    • @r this object for chaining
  • seek (double Ms)

    Seeks to the specified position in the media.

    • @p Ms is a double with the position in milliseconds.
    • @r this object for chaining
  • setVolume (double Vol)

    Sets the playback volume.

    • @p Vol is a double between 0.0 (silent) and 1.0 (full volume).
    • @r this object for chaining
  • getVolume ()

    Returns the current playback volume.

    • @r A double with the volume between 0.0 and 1.0.
  • setMute (bool Mute)

    Sets whether the player is muted without changing the volume value.

    • @p Mute is a bool with true to mute the player.
    • @r this object for chaining
  • isMute ()

    Returns whether the player is currently muted.

    • @r A bool with true if the player is muted.
  • setAutoPlay (bool Auto)

    Sets whether the player starts playback automatically when ready.

    • @p Auto is a bool with true to enable auto-play.
    • @r this object for chaining
  • setCycleCount (int Count)

    Sets how many times the media repeats before stopping.

    • @p Count is an int with the cycle count, or MediaPlayer.INDEFINITE to loop forever.
    • @r this object for chaining
  • setOnEndOfMedia (callback OnEnd)

    Sets a callback that fires when playback reaches the end of the media.

    • @p OnEnd is a callback to call when media playback ends.
    • @r this object for chaining
  • setOnReady (callback OnReady)

    Sets a callback that fires when the player is ready to begin playback.

    • @p OnReady is a callback to call when the player is ready.
    • @r this object for chaining
  • getStatus ()

    Returns the current status of the media player.

    • @r A string with the status, e.g., PLAYING, PAUSED, or STOPPED.
  • dispose ()

    Disposes of this MediaPlayer, releasing all associated resources.