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.

  • getAudioEqualizer ()

    Returns the AudioEqualizer associated with this player. Use it to adjust per-band gain on the audio output.

    • @r An AJO holding the javafx.scene.media.AudioEqualizer.
  • getError ()

    Returns the most recent player error, or null when no error has occurred.

    • @r An AJO holding the javafx.scene.media.MediaException, or null.
  • errorProperty ()

    Returns the read-only property holding the most recent player error.

    • @r A ReadOnlyObjectProperty AJO holding the MediaException.
  • setOnError (callback Cb)

    Sets a callback that fires when an error occurs in the player.

    • @p Cb is a callback invoked with no arguments.
    • @r this object
  • getOnError ()

    Returns the current onError handler.

    • @r An AJO holding the Runnable, or null.
  • onErrorProperty ()

    Returns the property holding the onError handler.

    • @r An ObjectProperty AJO holding the Runnable.
  • getMedia ()

    Returns the Media resource this player is bound to.

    • @r An AJO holding the javafx.scene.media.Media.
  • isAutoPlay ()

    Returns whether the player automatically starts playback once it is ready.

    • @r A bool with true when auto-play is enabled.
  • autoPlayProperty ()

    Returns the property holding the autoPlay flag.

    • @r A BooleanProperty AJO.
  • setRate (double Rate)

    Sets the playback rate. 1.0 is normal speed, values above 1.0 play faster, and values below 1.0 play slower.

    • @p Rate is a double with the playback rate.
    • @r this object
  • getRate ()

    Returns the requested playback rate.

    • @r A double with the playback rate.
  • rateProperty ()

    Returns the property holding the playback rate.

    • @r A DoubleProperty AJO.
  • getCurrentRate ()

    Returns the current actual playback rate, which may differ from the requested rate while seeking or buffering.

    • @r A double with the current rate.
  • currentRateProperty ()

    Returns the read-only property holding the current playback rate.

    • @r A ReadOnlyDoubleProperty AJO.
  • volumeProperty ()

    Returns the property holding the volume value.

    • @r A DoubleProperty AJO.
  • setBalance (double Balance)

    Sets the stereo balance. -1.0 is full left, 0.0 is centered, and 1.0 is full right.

    • @p Balance is a double between -1.0 and 1.0.
    • @r this object
  • getBalance ()

    Returns the stereo balance value.

    • @r A double between -1.0 and 1.0.
  • balanceProperty ()

    Returns the property holding the stereo balance.

    • @r A DoubleProperty AJO.
  • setStartTime (double Ms)

    Sets the start time used as the playback start position.

    • @p Ms is a double with the start time in milliseconds.
    • @r this object
  • getStartTime ()

    Returns the Duration used as the playback start position.

    • @r An AJO holding the javafx.util.Duration.
  • startTimeProperty ()

    Returns the property holding the start Duration. The wrapper seeds the property with the current getStartTime() value first because JavaFX lazy-initializes the underlying ObjectProperty with a null value, which leaves the field null and crashes calculateCycleDuration when the player later transitions to READY on the JavaFX Application Thread.

    • @r An ObjectProperty AJO holding the Duration.
  • setStopTime (double Ms)

    Sets the stop time used as the playback stop position.

    • @p Ms is a double with the stop time in milliseconds.
    • @r this object
  • getStopTime ()

    Returns the Duration used as the playback stop position.

    • @r An AJO holding the javafx.util.Duration.
  • stopTimeProperty ()

    Returns the property holding the stop Duration. The wrapper seeds the property with the current getStopTime() value first because JavaFX lazy-initializes the underlying ObjectProperty with a null value, which leaves the field null and crashes calculateCycleDuration when the player later transitions to READY on the JavaFX Application Thread.

    • @r An ObjectProperty AJO holding the Duration.
  • getCycleDuration ()

    Returns the Duration of a single playback cycle.

    • @r An AJO holding the javafx.util.Duration.
  • cycleDurationProperty ()

    Returns the read-only property holding the cycle Duration.

    • @r A ReadOnlyObjectProperty AJO holding the Duration.
  • getTotalDuration ()

    Returns the total Duration of all configured playback cycles.

    • @r An AJO holding the javafx.util.Duration.
  • totalDurationProperty ()

    Returns the read-only property holding the total Duration.

    • @r A ReadOnlyObjectProperty AJO holding the Duration.
  • getCurrentTime ()

    Returns the current playback position as a Duration.

    • @r An AJO holding the javafx.util.Duration.
  • currentTimeProperty ()

    Returns the read-only property holding the current playback Duration.

    • @r A ReadOnlyObjectProperty AJO holding the Duration.
  • statusProperty ()

    Returns the read-only property holding the player Status enum value.

    • @r A ReadOnlyObjectProperty AJO holding the Status.
  • getBufferProgressTime ()

    Returns the Duration up to which the player has buffered media.

    • @r An AJO holding the javafx.util.Duration.
  • bufferProgressTimeProperty ()

    Returns the read-only property holding the buffer progress Duration.

    • @r A ReadOnlyObjectProperty AJO holding the Duration.
  • getCycleCount ()

    Returns the configured cycle count, or MediaPlayer.INDEFINITE for an infinite loop.

    • @r An int with the cycle count.
  • cycleCountProperty ()

    Returns the property holding the cycle count.

    • @r An IntegerProperty AJO.
  • getCurrentCount ()

    Returns the number of cycles that have completed so far.

    • @r An int with the current cycle count.
  • currentCountProperty ()

    Returns the read-only property holding the current cycle count.

    • @r A ReadOnlyIntegerProperty AJO.
  • muteProperty ()

    Returns the property holding the mute flag.

    • @r A BooleanProperty AJO.
  • setOnMarker (callback Cb)

    Sets a callback that fires when a named media marker is reached.

    • @p Cb is a callback that receives the MediaMarkerEvent.
    • @r this object
  • getOnMarker ()

    Returns the current onMarker handler.

    • @r An AJO holding the EventHandler, or null.
  • onMarkerProperty ()

    Returns the property holding the onMarker handler.

    • @r An ObjectProperty AJO holding the EventHandler.
  • getOnEndOfMedia ()

    Returns the current onEndOfMedia handler.

    • @r An AJO holding the Runnable, or null.
  • onEndOfMediaProperty ()

    Returns the property holding the onEndOfMedia handler.

    • @r An ObjectProperty AJO holding the Runnable.
  • getOnReady ()

    Returns the current onReady handler.

    • @r An AJO holding the Runnable, or null.
  • onReadyProperty ()

    Returns the property holding the onReady handler.

    • @r An ObjectProperty AJO holding the Runnable.
  • setOnPlaying (callback Cb)

    Sets a callback that fires when playback starts.

    • @p Cb is a callback invoked with no arguments.
    • @r this object
  • getOnPlaying ()

    Returns the current onPlaying handler.

    • @r An AJO holding the Runnable, or null.
  • onPlayingProperty ()

    Returns the property holding the onPlaying handler.

    • @r An ObjectProperty AJO holding the Runnable.
  • setOnPaused (callback Cb)

    Sets a callback that fires when playback pauses.

    • @p Cb is a callback invoked with no arguments.
    • @r this object
  • getOnPaused ()

    Returns the current onPaused handler.

    • @r An AJO holding the Runnable, or null.
  • onPausedProperty ()

    Returns the property holding the onPaused handler.

    • @r An ObjectProperty AJO holding the Runnable.
  • setOnStopped (callback Cb)

    Sets a callback that fires when playback stops.

    • @p Cb is a callback invoked with no arguments.
    • @r this object
  • getOnStopped ()

    Returns the current onStopped handler.

    • @r An AJO holding the Runnable, or null.
  • onStoppedProperty ()

    Returns the property holding the onStopped handler.

    • @r An ObjectProperty AJO holding the Runnable.
  • setOnHalted (callback Cb)

    Sets a callback that fires when the player enters the HALTED state.

    • @p Cb is a callback invoked with no arguments.
    • @r this object
  • getOnHalted ()

    Returns the current onHalted handler.

    • @r An AJO holding the Runnable, or null.
  • onHaltedProperty ()

    Returns the property holding the onHalted handler.

    • @r An ObjectProperty AJO holding the Runnable.
  • setOnRepeat (callback Cb)

    Sets a callback that fires when a playback cycle repeats.

    • @p Cb is a callback invoked with no arguments.
    • @r this object
  • getOnRepeat ()

    Returns the current onRepeat handler.

    • @r An AJO holding the Runnable, or null.
  • onRepeatProperty ()

    Returns the property holding the onRepeat handler.

    • @r An ObjectProperty AJO holding the Runnable.
  • setOnStalled (callback Cb)

    Sets a callback that fires when playback stalls waiting for data.

    • @p Cb is a callback invoked with no arguments.
    • @r this object
  • getOnStalled ()

    Returns the current onStalled handler.

    • @r An AJO holding the Runnable, or null.
  • onStalledProperty ()

    Returns the property holding the onStalled handler.

    • @r An ObjectProperty AJO holding the Runnable.
  • setAudioSpectrumNumBands (int Bands)

    Sets how many frequency bands the audio spectrum analyser computes.

    • @p Bands is an int with the band count.
    • @r this object
  • getAudioSpectrumNumBands ()

    Returns the number of frequency bands the audio spectrum analyser computes.

    • @r An int with the band count.
  • audioSpectrumNumBandsProperty ()

    Returns the property holding the audio spectrum band count.

    • @r An IntegerProperty AJO.
  • setAudioSpectrumInterval (double Interval)

    Sets the interval in seconds between audio spectrum updates.

    • @p Interval is a double with the update interval in seconds.
    • @r this object
  • getAudioSpectrumInterval ()

    Returns the audio spectrum update interval in seconds.

    • @r A double with the interval in seconds.
  • audioSpectrumIntervalProperty ()

    Returns the property holding the audio spectrum update interval.

    • @r A DoubleProperty AJO.
  • setAudioSpectrumThreshold (int Threshold)

    Sets the minimum level (in dB) reported by the audio spectrum analyser.

    • @p Threshold is an int with the threshold in decibels.
    • @r this object
  • getAudioSpectrumThreshold ()

    Returns the audio spectrum threshold in decibels.

    • @r An int with the threshold in decibels.
  • audioSpectrumThresholdProperty ()

    Returns the property holding the audio spectrum threshold.

    • @r An IntegerProperty AJO.
  • setAudioSpectrumListener (object ListenerObj)

    Sets the AudioSpectrumListener that receives spectrum data on each update interval.

    • @p ListenerObj is an AJO holding a javafx.scene.media.AudioSpectrumListener.
    • @r this object
  • getAudioSpectrumListener ()

    Returns the current AudioSpectrumListener.

    • @r An AJO holding the AudioSpectrumListener, or null.
  • audioSpectrumListenerProperty ()

    Returns the property holding the AudioSpectrumListener.

    • @r An ObjectProperty AJO holding the AudioSpectrumListener.