Interface MediaPlayer

All Superinterfaces:
javafx.event.EventTarget, MediaEngine
All Known Implementing Classes:
FXMediaPlayer, WebMediaPlayer

public interface MediaPlayer extends MediaEngine, javafx.event.EventTarget
The MediaPlayer offers functionalities for media playback across desktop/mobile and web platforms with ease.

This class equips the user with controls for managing media. It is typically utilized with the MediaSource and MediaView classes to control and display media playback. Since MediaPlayer doesn't incorporate any visual elements, it should be used with the MediaView class to view any present video track.

MediaPlayer includes play(), pause(), stop(), and seek() controls for playback functionalities. It also supports the rate and autoPlay properties applicable to all media types. The class provides the mute and volume properties to manage audio playback characteristics. The status property can be used to ascertain the current status of the MediaPlayer, and the currentTime property helps determine the current time position of the media. The playback rate can be adjusted using the rate property, while the currentRate property offers information about the current rate during playback.

For media with a finite duration, playback can be positioned at any point in time between 0.0 and the duration of the media. MediaPlayer further refines this by adding the startTime and stopTime properties, thereby defining a virtual media source with time position constrained between [startTime,stopTime]. Media playback starts at startTime and continues till stopTime. The interval specified by these two endpoints is termed a cycle, with duration being the difference between the stop and start times. This cycle can be set to repeat a certain or indefinite number of times. The total duration of media playback equals the product of the cycle duration and the number of times the cycle is played. If the stop time of the cycle is reached and the cycle is set to be played again, the event handler registered with the onRepeat property is invoked. If the stop time is reached, then the event handler registered with the onEndOfMedia property is invoked regardless of whether the cycle is set to be repeated or not. A zero-relative index of the currently playing cycle is maintained by currentCount.

All operations of a MediaPlayer are inherently asynchronous. Upon loading the given MediaSource, use the setOnReady(EventHandler) to get notified when the MediaPlayer is ready for playback. Other event handlers like setOnPlaying(EventHandler), setOnPaused(EventHandler), setOnStopped(EventHandler), setOnEndOfMedia(EventHandler), and setOnStalled(EventHandler) can be used to get notified of the corresponding events.

A single MediaPlayer object can be shared among multiple MediaViews without affecting the player. Specifically, the property settings of the view don't influence media playback.

Author:
Besmir Beqiri
See Also:
  • Property Summary

    Properties
    Type
    Property
    Description
    javafx.beans.property.BooleanProperty
    Whether playing should start as soon as possible.
    javafx.beans.property.ReadOnlyIntegerProperty
    The number of completed playback cycles.
    javafx.beans.property.ReadOnlyDoubleProperty
    The current rate of playback regardless of settings.
    javafx.beans.property.ReadOnlyObjectProperty<javafx.util.Duration>
    The current media playback time.
    javafx.beans.property.IntegerProperty
    The number of times the media will be played.
    javafx.beans.property.ReadOnlyObjectProperty<javafx.util.Duration>
    The amount of time between the startTime and stopTime of this player.
    javafx.beans.property.ReadOnlyObjectProperty<javafx.util.Duration>
    The total duration of play time if allowed to play until finished.
    javafx.beans.property.ReadOnlyObjectProperty<MediaPlayerException>
    Observable property set to a MediaPlayerException if an error occurs.
    javafx.beans.property.ReadOnlyObjectProperty<MediaSource>
    The media source for the current player.
    javafx.beans.property.BooleanProperty
    Whether the player audio is muted.
    javafx.beans.property.ObjectProperty<javafx.event.EventHandler<MediaPlayerEvent>>
    Event handler invoked when the end of media is reached naturally.
    javafx.beans.property.ObjectProperty<javafx.event.EventHandler<MediaPlayerEvent>>
    Event handler invoked when an error occurs.
    javafx.beans.property.ObjectProperty<javafx.event.EventHandler<MediaPlayerEvent>>
    Event handler invoked when the status changes to PAUSED.
    javafx.beans.property.ObjectProperty<javafx.event.EventHandler<MediaPlayerEvent>>
    Event handler invoked when the status changes to PLAYING.
    javafx.beans.property.ObjectProperty<javafx.event.EventHandler<MediaPlayerEvent>>
    Event handler invoked when the status changes to READY.
    javafx.beans.property.ObjectProperty<javafx.event.EventHandler<MediaPlayerEvent>>
    Event handler invoked when the player currentTime reaches stopTime and will be repeating.
    javafx.beans.property.ObjectProperty<javafx.event.EventHandler<MediaPlayerEvent>>
    Event handler invoked when the status changes to STALLED.
    javafx.beans.property.ObjectProperty<javafx.event.EventHandler<MediaPlayerEvent>>
    Event handler invoked when the status changes to STOPPED.
    javafx.beans.property.DoubleProperty
    The rate at which the media should be played.
    javafx.beans.property.ObjectProperty<javafx.util.Duration>
    The time offset where media should start playing, or restart from when repeating.
    javafx.beans.property.ReadOnlyObjectProperty<javafx.scene.media.MediaPlayer.Status>
    The current status of the MediaPlayer.
    javafx.beans.property.ObjectProperty<javafx.util.Duration>
    The time offset where media should stop playing or restart when repeating.
    javafx.beans.property.ReadOnlyObjectProperty<javafx.util.Duration>
    The total amount of play time if allowed to play until finished.
    javafx.beans.property.DoubleProperty
     
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
    A value representing an effectively infinite number of playback cycles.
  • Method Summary

    Modifier and Type
    Method
    Description
    javafx.beans.property.BooleanProperty
    Whether playing should start as soon as possible.
    create(javafx.stage.Stage stage, MediaSource mediaSource)
    Creates a media player.
    javafx.beans.property.ReadOnlyIntegerProperty
    The number of completed playback cycles.
    javafx.beans.property.ReadOnlyDoubleProperty
    The current rate of playback regardless of settings.
    javafx.beans.property.ReadOnlyObjectProperty<javafx.util.Duration>
    The current media playback time.
    javafx.beans.property.IntegerProperty
    The number of times the media will be played.
    javafx.beans.property.ReadOnlyObjectProperty<javafx.util.Duration>
    The amount of time between the startTime and stopTime of this player.
    javafx.beans.property.ReadOnlyObjectProperty<javafx.util.Duration>
    The total duration of play time if allowed to play until finished.
    javafx.beans.property.ReadOnlyObjectProperty<MediaPlayerException>
    Observable property set to a MediaPlayerException if an error occurs.
    int
    Retrieves the index of the current cycle.
    double
    Retrieves the current playback rate.
    javafx.util.Duration
    Retrieves the current media time.
    int
    Retrieves the cycle count.
    javafx.util.Duration
    Retrieves the cycle duration in seconds.
    javafx.util.Duration
    Gets the duration for the given media source.
    Retrieve the value of the error property or null if there is no error.
    Retrieves the current media source.
    javafx.event.EventHandler<MediaPlayerEvent>
    Retrievers the event handler invoked when the end of media is reached naturally.
    javafx.event.EventHandler<MediaPlayerEvent>
    Retrieves the event handler for errors.
    javafx.event.EventHandler<MediaPlayerEvent>
    Retrieves the MediaPlayer.Status.PAUSED event handler.
    javafx.event.EventHandler<MediaPlayerEvent>
    Retrieves the MediaPlayer.Status.PLAYING event handler.
    javafx.event.EventHandler<MediaPlayerEvent>
    Retrieves the MediaPlayer.Status.READY event handler.
    javafx.event.EventHandler<MediaPlayerEvent>
    Retrieves the repeat event handler.
    javafx.event.EventHandler<MediaPlayerEvent>
    Retrieves the MediaPlayer.Status.STALLED event handler.
    javafx.event.EventHandler<MediaPlayerEvent>
    Retrieves the MediaPlayer.Status.STOPPED event handler.
    double
    Retrieves the playback rate.
    javafx.util.Duration
    Retrieves the start time.
    javafx.scene.media.MediaPlayer.Status
    Retrieves the current player status.
    javafx.util.Duration
    Retrieves the stop time.
    javafx.util.Duration
    Retrieves the total playback duration including all cycles (repetitions).
    double
    Retrieves the audio playback volume.
    boolean
    Retrieves the autoPlay property value.
    boolean
    Retrieves the muteProperty value.
    javafx.beans.property.ReadOnlyObjectProperty<MediaSource>
    The media source for the current player.
    javafx.beans.property.BooleanProperty
    Whether the player audio is muted.
    javafx.beans.property.ObjectProperty<javafx.event.EventHandler<MediaPlayerEvent>>
    Event handler invoked when the end of media is reached naturally.
    javafx.beans.property.ObjectProperty<javafx.event.EventHandler<MediaPlayerEvent>>
    Event handler invoked when an error occurs.
    javafx.beans.property.ObjectProperty<javafx.event.EventHandler<MediaPlayerEvent>>
    Event handler invoked when the status changes to PAUSED.
    javafx.beans.property.ObjectProperty<javafx.event.EventHandler<MediaPlayerEvent>>
    Event handler invoked when the status changes to PLAYING.
    javafx.beans.property.ObjectProperty<javafx.event.EventHandler<MediaPlayerEvent>>
    Event handler invoked when the status changes to READY.
    javafx.beans.property.ObjectProperty<javafx.event.EventHandler<MediaPlayerEvent>>
    Event handler invoked when the player currentTime reaches stopTime and will be repeating.
    javafx.beans.property.ObjectProperty<javafx.event.EventHandler<MediaPlayerEvent>>
    Event handler invoked when the status changes to STALLED.
    javafx.beans.property.ObjectProperty<javafx.event.EventHandler<MediaPlayerEvent>>
    Event handler invoked when the status changes to STOPPED.
    void
    Pauses the player.
    void
    Starts playing the media.
    javafx.beans.property.DoubleProperty
    The rate at which the media should be played.
    void
    seek(javafx.util.Duration seekTime)
    Seeks the player to a new playback time.
    void
    setAutoPlay(boolean value)
    Sets the autoPlay property value.
    void
    setCycleCount(int value)
    Sets the cycle count.
    void
    setMute(boolean value)
    Sets the muteProperty value.
    void
    setOnEndOfMedia(javafx.event.EventHandler<MediaPlayerEvent> value)
    Sets the event handler invoked when the end of media is reached naturally.
    void
    setOnError(javafx.event.EventHandler<MediaPlayerEvent> value)
    Sets the event handler to be called when an error occurs.
    void
    setOnPaused(javafx.event.EventHandler<MediaPlayerEvent> value)
    Sets the MediaPlayer.Status.PAUSED event handler.
    void
    setOnPlaying(javafx.event.EventHandler<MediaPlayerEvent> value)
    Sets the MediaPlayer.Status.PLAYING event handler.
    void
    setOnReady(javafx.event.EventHandler<MediaPlayerEvent> value)
    Sets the MediaPlayer.Status.READY event handler.
    void
    setOnRepeat(javafx.event.EventHandler<MediaPlayerEvent> value)
    Sets the repeat event handler.
    void
    setOnStalled(javafx.event.EventHandler<MediaPlayerEvent> value)
    Sets the MediaPlayer.Status.STALLED event handler.
    void
    setOnStopped(javafx.event.EventHandler<MediaPlayerEvent> value)
    Sets the MediaPlayer.Status.STOPPED event handler.
    void
    setRate(double value)
    Sets the playback rate to the supplied value.
    void
    setStartTime(javafx.util.Duration value)
    Sets the start time.
    void
    setStopTime(javafx.util.Duration value)
    Sets the stop time.
    void
    setVolume(double value)
    Sets the audio playback volume.
    javafx.beans.property.ObjectProperty<javafx.util.Duration>
    The time offset where media should start playing, or restart from when repeating.
    javafx.beans.property.ReadOnlyObjectProperty<javafx.scene.media.MediaPlayer.Status>
    The current status of the MediaPlayer.
    void
    Stops playing the media.
    javafx.beans.property.ObjectProperty<javafx.util.Duration>
    The time offset where media should stop playing or restart when repeating.
    javafx.beans.property.ReadOnlyObjectProperty<javafx.util.Duration>
    The total amount of play time if allowed to play until finished.
    javafx.beans.property.DoubleProperty
     

    Methods inherited from interface javafx.event.EventTarget

    buildEventDispatchChain
  • Property Details

    • mediaSource

      javafx.beans.property.ReadOnlyObjectProperty<MediaSource> mediaSourceProperty
      The media source for the current player. It holds the information on where it resource is located and accessed either via a string form URI locally, or via WebAPI.JSFile remotely.
      See Also:
    • autoPlay

      javafx.beans.property.BooleanProperty autoPlayProperty
      Whether playing should start as soon as possible. For a new player this will occur once the player has reached the READY state. The default value is false.
      See Also:
    • status

      javafx.beans.property.ReadOnlyObjectProperty<javafx.scene.media.MediaPlayer.Status> statusProperty
      The current status of the MediaPlayer.
      See Also:
    • duration

      javafx.beans.property.ReadOnlyObjectProperty<javafx.util.Duration> durationProperty
      The total duration of play time if allowed to play until finished. If the Media duration is Duration.UNKNOWN, then this will likewise be Duration.UNKNOWN.
      See Also:
    • volume

      javafx.beans.property.DoubleProperty volumeProperty
      See Also:
    • mute

      javafx.beans.property.BooleanProperty muteProperty
      Whether the player audio is muted. A value of true indicates that audio is not being produced. The value of this property has no effect on volume, i.e., if the audio is muted and then unmuted, audio playback will resume at the same audible level provided of course that the volume property has not been modified meanwhile. The default value is false.
      See Also:
    • rate

      javafx.beans.property.DoubleProperty rateProperty
      The rate at which the media should be played. For example, a rate of 1.0 plays the media at its normal (encoded) playback rate, 2.0 plays back at twice the normal rate, etc. The currently supported range of rates is [0.0, 8.0]. The default value is 1.0.
      See Also:
    • currentRate

      javafx.beans.property.ReadOnlyDoubleProperty currentRateProperty
      The current rate of playback regardless of settings. For example, if rate is set to 1.0 and the player is paused or stalled, then currentRate will be zero.
      See Also:
    • currentTime

      javafx.beans.property.ReadOnlyObjectProperty<javafx.util.Duration> currentTimeProperty
      The current media playback time. This property is read-only: use seek(Duration) to change playback to a different stream position.
      See Also:
    • startTime

      javafx.beans.property.ObjectProperty<javafx.util.Duration> startTimeProperty
      The time offset where media should start playing, or restart from when repeating. When playback is stopped, the current time is reset to this value. If this value is positive, then the first time the media is played there might be a delay before playing begins unless the play position can be set to an arbitrary time within the media. This could occur for example for a video which does not contain a lookup table of the offsets of intra-frames in the video stream. In such a case the video frames would need to be skipped over until the position of the first intra-frame before the start time was reached. The default value is Duration.ZERO.

      Constraints: 0 ≤ startTime < stopTime

      See Also:
    • stopTime

      javafx.beans.property.ObjectProperty<javafx.util.Duration> stopTimeProperty
      The time offset where media should stop playing or restart when repeating. The default value is getDuration().

      Constraints: startTime < stopTime ≤ MediaPlayer.duration

      See Also:
    • cycleCount

      javafx.beans.property.IntegerProperty cycleCountProperty
      The number of times the media will be played. By default, cycleCount is set to 1 meaning the media will only be played once. Setting cycleCount to a value greater than 1 will cause the media to play the given number of times or until stopped. If set to INDEFINITE, playback will repeat until stop() or pause() is called.

      constraints: cycleCount ≥ 1

      See Also:
    • currentCount

      javafx.beans.property.ReadOnlyIntegerProperty currentCountProperty
      The number of completed playback cycles. On the first pass, the value should be 0. On the second pass, the value should be 1 and so on. It is incremented at the end of each cycle just prior to seeking back to startTime, i.e., when stopTime or the end of media has been reached.
      See Also:
    • cycleDuration

      javafx.beans.property.ReadOnlyObjectProperty<javafx.util.Duration> cycleDurationProperty
      The amount of time between the startTime and stopTime of this player. For the total duration of the MediaSource use the MediaPlayer.duration property.
      See Also:
    • totalDuration

      javafx.beans.property.ReadOnlyObjectProperty<javafx.util.Duration> totalDurationProperty
      The total amount of play time if allowed to play until finished. If cycleCount is set to INDEFINITE then this will also be INDEFINITE. If the media resource duration is UNKNOWN, then this will likewise be UNKNOWN. Otherwise, total duration will be the product of cycleDuration and cycleCount.
      See Also:
    • onReady

      javafx.beans.property.ObjectProperty<javafx.event.EventHandler<MediaPlayerEvent>> onReadyProperty
      Event handler invoked when the status changes to READY.
      See Also:
    • onPlaying

      javafx.beans.property.ObjectProperty<javafx.event.EventHandler<MediaPlayerEvent>> onPlayingProperty
      Event handler invoked when the status changes to PLAYING.
      See Also:
    • onPaused

      javafx.beans.property.ObjectProperty<javafx.event.EventHandler<MediaPlayerEvent>> onPausedProperty
      Event handler invoked when the status changes to PAUSED.
      See Also:
    • onStopped

      javafx.beans.property.ObjectProperty<javafx.event.EventHandler<MediaPlayerEvent>> onStoppedProperty
      Event handler invoked when the status changes to STOPPED.
      See Also:
    • onStalled

      javafx.beans.property.ObjectProperty<javafx.event.EventHandler<MediaPlayerEvent>> onStalledProperty
      Event handler invoked when the status changes to STALLED.
      See Also:
    • onEndOfMedia

      javafx.beans.property.ObjectProperty<javafx.event.EventHandler<MediaPlayerEvent>> onEndOfMediaProperty
      Event handler invoked when the end of media is reached naturally.
      See Also:
    • onRepeat

      javafx.beans.property.ObjectProperty<javafx.event.EventHandler<MediaPlayerEvent>> onRepeatProperty
      Event handler invoked when the player currentTime reaches stopTime and will be repeating. This callback is made prior to seeking back to startTime.
      See Also:
    • onError

      javafx.beans.property.ObjectProperty<javafx.event.EventHandler<MediaPlayerEvent>> onErrorProperty
      Event handler invoked when an error occurs.
      See Also:
    • error

      javafx.beans.property.ReadOnlyObjectProperty<MediaPlayerException> errorProperty
      Observable property set to a MediaPlayerException if an error occurs.
      See Also:
  • Field Details

    • INDEFINITE

      static final int INDEFINITE
      A value representing an effectively infinite number of playback cycles. When cycleCount is set to this value, the player will replay the MediaSource until stopped or paused.
      See Also:
  • Method Details

    • create

      static MediaPlayer create(javafx.stage.Stage stage, MediaSource mediaSource)
      Creates a media player. If the application is running in a browser via JPro server, then a web version of media player is returned. If the application is not running inside the browser than a desktop version of the media player is returned.
      Parameters:
      stage - the application stage
      mediaSource - the media source
      Returns:
      a MediaPlayer object.
    • getMediaSource

      MediaSource getMediaSource()
      Retrieves the current media source.
      Returns:
      MediaSource object
    • mediaSourceProperty

      javafx.beans.property.ReadOnlyObjectProperty<MediaSource> mediaSourceProperty()
      The media source for the current player. It holds the information on where it resource is located and accessed either via a string form URI locally, or via WebAPI.JSFile remotely.
      Returns:
      the mediaSource property
      See Also:
    • setAutoPlay

      void setAutoPlay(boolean value)
      Sets the autoPlay property value.
      Parameters:
      value - whether to enable auto-playback
    • isAutoPlay

      boolean isAutoPlay()
      Retrieves the autoPlay property value.
      Returns:
      the value.
    • autoPlayProperty

      javafx.beans.property.BooleanProperty autoPlayProperty()
      Whether playing should start as soon as possible. For a new player this will occur once the player has reached the READY state. The default value is false.
      Returns:
      the autoPlay property
      See Also:
    • getStatus

      javafx.scene.media.MediaPlayer.Status getStatus()
      Retrieves the current player status.
      Returns:
      the playback MediaPlayer.Status
    • statusProperty

      javafx.beans.property.ReadOnlyObjectProperty<javafx.scene.media.MediaPlayer.Status> statusProperty()
      The current status of the MediaPlayer.
      Returns:
      the status property
      See Also:
    • getDuration

      javafx.util.Duration getDuration()
      Gets the duration for the given media source. If the duration cannot be obtained when this method is invoked, a Duration.UNKNOWN value will be returned.
    • durationProperty

      javafx.beans.property.ReadOnlyObjectProperty<javafx.util.Duration> durationProperty()
      The total duration of play time if allowed to play until finished. If the Media duration is Duration.UNKNOWN, then this will likewise be Duration.UNKNOWN.
      Returns:
      the duration of the media
      See Also:
    • getVolume

      double getVolume()
      Retrieves the audio playback volume. The default value is 1.0.
      Returns:
      the audio volume
    • setVolume

      void setVolume(double value)
      Sets the audio playback volume. Its effect will be clamped to the range [0.0, 1.0].
      Parameters:
      value - the volume
    • volumeProperty

      javafx.beans.property.DoubleProperty volumeProperty()
      Returns:
      the volume property
      See Also:
    • isMute

      boolean isMute()
      Retrieves the muteProperty value.
      Returns:
      the mute setting
    • setMute

      void setMute(boolean value)
      Sets the muteProperty value.
      Parameters:
      value - the mute setting
    • muteProperty

      javafx.beans.property.BooleanProperty muteProperty()
      Whether the player audio is muted. A value of true indicates that audio is not being produced. The value of this property has no effect on volume, i.e., if the audio is muted and then unmuted, audio playback will resume at the same audible level provided of course that the volume property has not been modified meanwhile. The default value is false.
      Returns:
      the mute property
      See Also:
    • getRate

      double getRate()
      Retrieves the playback rate.
      Returns:
      the playback rate
    • setRate

      void setRate(double value)
      Sets the playback rate to the supplied value. Its effect will be clamped to the range [0.0, 8.0]. Invoking this method will have no effect if media duration is Duration.INDEFINITE.
      Parameters:
      value - the playback rate
    • rateProperty

      javafx.beans.property.DoubleProperty rateProperty()
      The rate at which the media should be played. For example, a rate of 1.0 plays the media at its normal (encoded) playback rate, 2.0 plays back at twice the normal rate, etc. The currently supported range of rates is [0.0, 8.0]. The default value is 1.0.
      Returns:
      the rate property
      See Also:
    • getCurrentRate

      double getCurrentRate()
      Retrieves the current playback rate.
      Returns:
      the current rate
    • currentRateProperty

      javafx.beans.property.ReadOnlyDoubleProperty currentRateProperty()
      The current rate of playback regardless of settings. For example, if rate is set to 1.0 and the player is paused or stalled, then currentRate will be zero.
      Returns:
      the currentRate property
      See Also:
    • getCurrentTime

      javafx.util.Duration getCurrentTime()
      Retrieves the current media time.
      Returns:
      the current media time
    • currentTimeProperty

      javafx.beans.property.ReadOnlyObjectProperty<javafx.util.Duration> currentTimeProperty()
      The current media playback time. This property is read-only: use seek(Duration) to change playback to a different stream position.
      Returns:
      the current playback time
      See Also:
    • getStartTime

      javafx.util.Duration getStartTime()
      Retrieves the start time. The default value is Duration.ZERO.
      Returns:
      the start time
    • setStartTime

      void setStartTime(javafx.util.Duration value)
      Sets the start time. Its effect will be clamped to the range [Duration.ZEROstopTime). Invoking this method will have no effect if media duration is Duration.INDEFINITE.
      Parameters:
      value - the start time
    • startTimeProperty

      javafx.beans.property.ObjectProperty<javafx.util.Duration> startTimeProperty()
      The time offset where media should start playing, or restart from when repeating. When playback is stopped, the current time is reset to this value. If this value is positive, then the first time the media is played there might be a delay before playing begins unless the play position can be set to an arbitrary time within the media. This could occur for example for a video which does not contain a lookup table of the offsets of intra-frames in the video stream. In such a case the video frames would need to be skipped over until the position of the first intra-frame before the start time was reached. The default value is Duration.ZERO.

      Constraints: 0 ≤ startTime < stopTime

      Returns:
      the startTime property
      See Also:
    • getStopTime

      javafx.util.Duration getStopTime()
      Retrieves the stop time. The default value is getDuration(). Note that duration may have the value Duration.UNKNOWN if media initialization is not complete.
      Returns:
      the stop time
    • setStopTime

      void setStopTime(javafx.util.Duration value)
      Sets the stop time. Its effect will be clamped to the range (startTimeMedia.duration]. Invoking this method will have no effect if media duration is Duration.INDEFINITE.
      Parameters:
      value - the stop time
    • stopTimeProperty

      javafx.beans.property.ObjectProperty<javafx.util.Duration> stopTimeProperty()
      The time offset where media should stop playing or restart when repeating. The default value is getDuration().

      Constraints: startTime < stopTime ≤ MediaPlayer.duration

      Returns:
      the stopTime property
      See Also:
    • getCycleCount

      int getCycleCount()
      Retrieves the cycle count.
      Returns:
      the cycle count.
    • setCycleCount

      void setCycleCount(int value)
      Sets the cycle count. Its effect will be constrained to [1,Integer.MAX_VALUE]. Invoking this method will have no effect if media duration is Duration.INDEFINITE.
      Parameters:
      value - the cycle count
    • cycleCountProperty

      javafx.beans.property.IntegerProperty cycleCountProperty()
      The number of times the media will be played. By default, cycleCount is set to 1 meaning the media will only be played once. Setting cycleCount to a value greater than 1 will cause the media to play the given number of times or until stopped. If set to INDEFINITE, playback will repeat until stop() or pause() is called.

      constraints: cycleCount ≥ 1

      Returns:
      the cycleCount property
      See Also:
    • getCurrentCount

      int getCurrentCount()
      Retrieves the index of the current cycle.
      Returns:
      the current cycle index
    • currentCountProperty

      javafx.beans.property.ReadOnlyIntegerProperty currentCountProperty()
      The number of completed playback cycles. On the first pass, the value should be 0. On the second pass, the value should be 1 and so on. It is incremented at the end of each cycle just prior to seeking back to startTime, i.e., when stopTime or the end of media has been reached.
      Returns:
      the currentCount property
      See Also:
    • getCycleDuration

      javafx.util.Duration getCycleDuration()
      Retrieves the cycle duration in seconds.
      Returns:
      the cycle duration
    • cycleDurationProperty

      javafx.beans.property.ReadOnlyObjectProperty<javafx.util.Duration> cycleDurationProperty()
      The amount of time between the startTime and stopTime of this player. For the total duration of the MediaSource use the MediaPlayer.duration property.
      Returns:
      the cycleDuration property
      See Also:
    • getTotalDuration

      javafx.util.Duration getTotalDuration()
      Retrieves the total playback duration including all cycles (repetitions).
      Returns:
      the total playback duration
    • totalDurationProperty

      javafx.beans.property.ReadOnlyObjectProperty<javafx.util.Duration> totalDurationProperty()
      The total amount of play time if allowed to play until finished. If cycleCount is set to INDEFINITE then this will also be INDEFINITE. If the media resource duration is UNKNOWN, then this will likewise be UNKNOWN. Otherwise, total duration will be the product of cycleDuration and cycleCount.
      Returns:
      the totalDuration property
      See Also:
    • getOnReady

      javafx.event.EventHandler<MediaPlayerEvent> getOnReady()
      Retrieves the MediaPlayer.Status.READY event handler.
      Returns:
      the event handler or null.
    • setOnReady

      void setOnReady(javafx.event.EventHandler<MediaPlayerEvent> value)
      Sets the MediaPlayer.Status.READY event handler.
      Parameters:
      value - the event handler or null.
    • onReadyProperty

      javafx.beans.property.ObjectProperty<javafx.event.EventHandler<MediaPlayerEvent>> onReadyProperty()
      Event handler invoked when the status changes to READY.
      Returns:
      the onReady property
      See Also:
    • getOnPlaying

      javafx.event.EventHandler<MediaPlayerEvent> getOnPlaying()
      Retrieves the MediaPlayer.Status.PLAYING event handler.
      Returns:
      the event handler or null.
    • setOnPlaying

      void setOnPlaying(javafx.event.EventHandler<MediaPlayerEvent> value)
      Sets the MediaPlayer.Status.PLAYING event handler.
      Parameters:
      value - the event handler or null.
    • onPlayingProperty

      javafx.beans.property.ObjectProperty<javafx.event.EventHandler<MediaPlayerEvent>> onPlayingProperty()
      Event handler invoked when the status changes to PLAYING.
      Returns:
      the onPlaying property
      See Also:
    • getOnPaused

      javafx.event.EventHandler<MediaPlayerEvent> getOnPaused()
      Retrieves the MediaPlayer.Status.PAUSED event handler.
      Returns:
      the event handler or null.
    • setOnPaused

      void setOnPaused(javafx.event.EventHandler<MediaPlayerEvent> value)
      Sets the MediaPlayer.Status.PAUSED event handler.
      Parameters:
      value - the event handler or null.
    • onPausedProperty

      javafx.beans.property.ObjectProperty<javafx.event.EventHandler<MediaPlayerEvent>> onPausedProperty()
      Event handler invoked when the status changes to PAUSED.
      Returns:
      the onPaused property
      See Also:
    • getOnStopped

      javafx.event.EventHandler<MediaPlayerEvent> getOnStopped()
      Retrieves the MediaPlayer.Status.STOPPED event handler.
      Returns:
      the event handler or null.
    • setOnStopped

      void setOnStopped(javafx.event.EventHandler<MediaPlayerEvent> value)
      Sets the MediaPlayer.Status.STOPPED event handler.
      Parameters:
      value - the event handler or null.
    • onStoppedProperty

      javafx.beans.property.ObjectProperty<javafx.event.EventHandler<MediaPlayerEvent>> onStoppedProperty()
      Event handler invoked when the status changes to STOPPED.
      Returns:
      the onStopped property
      See Also:
    • getOnStalled

      javafx.event.EventHandler<MediaPlayerEvent> getOnStalled()
      Retrieves the MediaPlayer.Status.STALLED event handler.
      Returns:
      the event handler or null.
    • setOnStalled

      void setOnStalled(javafx.event.EventHandler<MediaPlayerEvent> value)
      Sets the MediaPlayer.Status.STALLED event handler.
      Parameters:
      value - the event handler or null.
    • onStalledProperty

      javafx.beans.property.ObjectProperty<javafx.event.EventHandler<MediaPlayerEvent>> onStalledProperty()
      Event handler invoked when the status changes to STALLED.
      Returns:
      the onStalled property
      See Also:
    • getOnEndOfMedia

      javafx.event.EventHandler<MediaPlayerEvent> getOnEndOfMedia()
      Retrievers the event handler invoked when the end of media is reached naturally.
      Returns:
      the event handler or null.
    • setOnEndOfMedia

      void setOnEndOfMedia(javafx.event.EventHandler<MediaPlayerEvent> value)
      Sets the event handler invoked when the end of media is reached naturally.
      Parameters:
      value - the event handler or null.
    • onEndOfMediaProperty

      javafx.beans.property.ObjectProperty<javafx.event.EventHandler<MediaPlayerEvent>> onEndOfMediaProperty()
      Event handler invoked when the end of media is reached naturally.
      Returns:
      the onEndOfMedia property
      See Also:
    • getOnRepeat

      javafx.event.EventHandler<MediaPlayerEvent> getOnRepeat()
      Retrieves the repeat event handler.
      Returns:
      the event handler or null.
    • setOnRepeat

      void setOnRepeat(javafx.event.EventHandler<MediaPlayerEvent> value)
      Sets the repeat event handler.
      Parameters:
      value - the event handler or null.
    • onRepeatProperty

      javafx.beans.property.ObjectProperty<javafx.event.EventHandler<MediaPlayerEvent>> onRepeatProperty()
      Event handler invoked when the player currentTime reaches stopTime and will be repeating. This callback is made prior to seeking back to startTime.
      Returns:
      the onRepeat property
      See Also:
    • getOnError

      javafx.event.EventHandler<MediaPlayerEvent> getOnError()
      Retrieves the event handler for errors.
      Returns:
      the event handler.
    • setOnError

      void setOnError(javafx.event.EventHandler<MediaPlayerEvent> value)
      Sets the event handler to be called when an error occurs.
      Parameters:
      value - the event handler or null.
    • onErrorProperty

      javafx.beans.property.ObjectProperty<javafx.event.EventHandler<MediaPlayerEvent>> onErrorProperty()
      Event handler invoked when an error occurs.
      Returns:
      the onError property
      See Also:
    • getError

      Retrieve the value of the error property or null if there is no error.
      Returns:
      a MediaPlayerException or null.
    • errorProperty

      javafx.beans.property.ReadOnlyObjectProperty<MediaPlayerException> errorProperty()
      Observable property set to a MediaPlayerException if an error occurs.
      Returns:
      the error property
      See Also:
    • play

      void play()
      Starts playing the media. If previously paused, then playback resumes where it was paused. If playback was stopped, playback starts from the startTime. When playing actually starts the status will be set to MediaPlayer.Status.PLAYING.
    • pause

      void pause()
      Pauses the player. Once the player is actually paused the status will be set to MediaPlayer.Status.PAUSED.
    • stop

      void stop()
      Stops playing the media. This operation resets playback to startTime and currentCount to zero. Once the player is actually stopped, the status will be set to MediaPlayer.Status.STOPPED. The only transitions out of STOPPED status are to MediaPlayer.Status.PAUSED and MediaPlayer.Status.PLAYING which occur after invoking pause() or play(), respectively. While stopped, the player will not respond to playback position changes requested by seek(Duration), although this is not the case for the player on the web when running via JPro.
    • seek

      void seek(javafx.util.Duration seekTime)
      Seeks the player to a new playback time. Invoking this method will have no effect while the player status is MediaPlayer.Status.STOPPED or media duration is Duration.INDEFINITE.

      The behavior of seek() is constrained as follows where start time and stop time indicate the effective lower and upper bounds, respectively, of media playback:

      MediaPlayer Seek Table
      seekTimeseek position
      nullno change
      Duration.UNKNOWNno change
      Duration.INDEFINITEstop time
      seekTime < start timestart time
      seekTime > stop timestop time
      start time ≤ seekTime ≤ stop timeseekTime
      Parameters:
      seekTime - the requested playback time