- All Superinterfaces:
javafx.event.EventTarget,MediaEngine
- All Known Implementing Classes:
FXMediaPlayer,WebMediaPlayer
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
PropertiesTypePropertyDescriptionjavafx.beans.property.BooleanPropertyWhether playing should start as soon as possible.javafx.beans.property.ReadOnlyIntegerPropertyThe number of completed playback cycles.javafx.beans.property.ReadOnlyDoublePropertyThe current rate of playback regardless of settings.javafx.beans.property.ReadOnlyObjectProperty<javafx.util.Duration> The current media playback time.javafx.beans.property.IntegerPropertyThe number of times the media will be played.javafx.beans.property.ReadOnlyObjectProperty<javafx.util.Duration> 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 aMediaPlayerExceptionif an error occurs.javafx.beans.property.ReadOnlyObjectProperty<MediaSource> The media source for the current player.javafx.beans.property.BooleanPropertyWhether 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 toPAUSED.javafx.beans.property.ObjectProperty<javafx.event.EventHandler<MediaPlayerEvent>> Event handler invoked when the status changes toPLAYING.javafx.beans.property.ObjectProperty<javafx.event.EventHandler<MediaPlayerEvent>> Event handler invoked when the status changes toREADY.javafx.beans.property.ObjectProperty<javafx.event.EventHandler<MediaPlayerEvent>> Event handler invoked when the playercurrentTimereachesstopTimeand will be repeating.javafx.beans.property.ObjectProperty<javafx.event.EventHandler<MediaPlayerEvent>> Event handler invoked when the status changes toSTALLED.javafx.beans.property.ObjectProperty<javafx.event.EventHandler<MediaPlayerEvent>> Event handler invoked when the status changes toSTOPPED.javafx.beans.property.DoublePropertyThe 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
FieldsModifier and TypeFieldDescriptionstatic final intA value representing an effectively infinite number of playback cycles. -
Method Summary
Modifier and TypeMethodDescriptionjavafx.beans.property.BooleanPropertyWhether playing should start as soon as possible.static MediaPlayercreate(javafx.stage.Stage stage, MediaSource mediaSource) Creates a media player.javafx.beans.property.ReadOnlyIntegerPropertyThe number of completed playback cycles.javafx.beans.property.ReadOnlyDoublePropertyThe current rate of playback regardless of settings.javafx.beans.property.ReadOnlyObjectProperty<javafx.util.Duration> The current media playback time.javafx.beans.property.IntegerPropertyThe number of times the media will be played.javafx.beans.property.ReadOnlyObjectProperty<javafx.util.Duration> 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 aMediaPlayerExceptionif an error occurs.intRetrieves the index of the current cycle.doubleRetrieves the current playback rate.javafx.util.DurationRetrieves the current media time.intRetrieves the cycle count.javafx.util.DurationRetrieves the cycle duration in seconds.javafx.util.DurationGets the duration for the given media source.getError()Retrieve the value of theerrorproperty ornullif 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 theMediaPlayer.Status.PAUSEDevent handler.javafx.event.EventHandler<MediaPlayerEvent> Retrieves theMediaPlayer.Status.PLAYINGevent handler.javafx.event.EventHandler<MediaPlayerEvent> Retrieves theMediaPlayer.Status.READYevent handler.javafx.event.EventHandler<MediaPlayerEvent> Retrieves the repeat event handler.javafx.event.EventHandler<MediaPlayerEvent> Retrieves theMediaPlayer.Status.STALLEDevent handler.javafx.event.EventHandler<MediaPlayerEvent> Retrieves theMediaPlayer.Status.STOPPEDevent handler.doublegetRate()Retrieves the playback rate.javafx.util.DurationRetrieves the start time.javafx.scene.media.MediaPlayer.StatusRetrieves the current player status.javafx.util.DurationRetrieves the stop time.javafx.util.DurationRetrieves the total playback duration including all cycles (repetitions).doubleRetrieves the audio playback volume.booleanRetrieves theautoPlayproperty value.booleanisMute()Retrieves the muteProperty value.javafx.beans.property.ReadOnlyObjectProperty<MediaSource> The media source for the current player.javafx.beans.property.BooleanPropertyWhether 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 toPAUSED.javafx.beans.property.ObjectProperty<javafx.event.EventHandler<MediaPlayerEvent>> Event handler invoked when the status changes toPLAYING.javafx.beans.property.ObjectProperty<javafx.event.EventHandler<MediaPlayerEvent>> Event handler invoked when the status changes toREADY.javafx.beans.property.ObjectProperty<javafx.event.EventHandler<MediaPlayerEvent>> Event handler invoked when the playercurrentTimereachesstopTimeand will be repeating.javafx.beans.property.ObjectProperty<javafx.event.EventHandler<MediaPlayerEvent>> Event handler invoked when the status changes toSTALLED.javafx.beans.property.ObjectProperty<javafx.event.EventHandler<MediaPlayerEvent>> Event handler invoked when the status changes toSTOPPED.voidpause()Pauses the player.voidplay()Starts playing the media.javafx.beans.property.DoublePropertyThe rate at which the media should be played.voidseek(javafx.util.Duration seekTime) Seeks the player to a new playback time.voidsetAutoPlay(boolean value) Sets theautoPlayproperty value.voidsetCycleCount(int value) Sets the cycle count.voidsetMute(boolean value) Sets the muteProperty value.voidsetOnEndOfMedia(javafx.event.EventHandler<MediaPlayerEvent> value) Sets the event handler invoked when the end of media is reached naturally.voidsetOnError(javafx.event.EventHandler<MediaPlayerEvent> value) Sets the event handler to be called when an error occurs.voidsetOnPaused(javafx.event.EventHandler<MediaPlayerEvent> value) Sets theMediaPlayer.Status.PAUSEDevent handler.voidsetOnPlaying(javafx.event.EventHandler<MediaPlayerEvent> value) Sets theMediaPlayer.Status.PLAYINGevent handler.voidsetOnReady(javafx.event.EventHandler<MediaPlayerEvent> value) Sets theMediaPlayer.Status.READYevent handler.voidsetOnRepeat(javafx.event.EventHandler<MediaPlayerEvent> value) Sets the repeat event handler.voidsetOnStalled(javafx.event.EventHandler<MediaPlayerEvent> value) Sets theMediaPlayer.Status.STALLEDevent handler.voidsetOnStopped(javafx.event.EventHandler<MediaPlayerEvent> value) Sets theMediaPlayer.Status.STOPPEDevent handler.voidsetRate(double value) Sets the playback rate to the supplied value.voidsetStartTime(javafx.util.Duration value) Sets the start time.voidsetStopTime(javafx.util.Duration value) Sets the stop time.voidsetVolume(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.voidstop()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.DoublePropertyMethods inherited from interface javafx.event.EventTarget
buildEventDispatchChain
-
Property Details
-
mediaSource
javafx.beans.property.ReadOnlyObjectProperty<MediaSource> mediaSourcePropertyThe 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 viaWebAPI.JSFileremotely.- See Also:
-
autoPlay
javafx.beans.property.BooleanProperty autoPlayPropertyWhether 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 isfalse.- See Also:
-
status
javafx.beans.property.ReadOnlyObjectProperty<javafx.scene.media.MediaPlayer.Status> statusPropertyThe current status of the MediaPlayer.- See Also:
-
duration
javafx.beans.property.ReadOnlyObjectProperty<javafx.util.Duration> durationPropertyThe total duration of play time if allowed to play until finished. If the Media duration isDuration.UNKNOWN, then this will likewise beDuration.UNKNOWN.- See Also:
-
volume
javafx.beans.property.DoubleProperty volumeProperty- See Also:
-
mute
javafx.beans.property.BooleanProperty mutePropertyWhether the player audio is muted. A value oftrueindicates that audio is not being produced. The value of this property has no effect onvolume, i.e., if the audio is muted and then unmuted, audio playback will resume at the same audible level provided of course that thevolumeproperty has not been modified meanwhile. The default value isfalse.- See Also:
-
rate
javafx.beans.property.DoubleProperty ratePropertyThe rate at which the media should be played. For example, a rate of1.0plays the media at its normal (encoded) playback rate,2.0plays back at twice the normal rate, etc. The currently supported range of rates is[0.0, 8.0]. The default value is1.0.- See Also:
-
currentRate
javafx.beans.property.ReadOnlyDoubleProperty currentRatePropertyThe current rate of playback regardless of settings. For example, ifrateis set to 1.0 and the player is paused or stalled, thencurrentRatewill be zero.- See Also:
-
currentTime
javafx.beans.property.ReadOnlyObjectProperty<javafx.util.Duration> currentTimePropertyThe current media playback time. This property is read-only: useseek(Duration)to change playback to a different stream position.- See Also:
-
startTime
javafx.beans.property.ObjectProperty<javafx.util.Duration> startTimePropertyThe 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 isDuration.ZERO.Constraints:
0 ≤ startTime <stopTime- See Also:
-
stopTime
javafx.beans.property.ObjectProperty<javafx.util.Duration> stopTimePropertyThe 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 cycleCountPropertyThe number of times the media will be played. By default,cycleCountis set to1meaning the media will only be played once. SettingcycleCountto a value greater than 1 will cause the media to play the given number of times or until stopped. If set toINDEFINITE, playback will repeat until stop() or pause() is called.constraints:
cycleCount ≥ 1- See Also:
-
currentCount
javafx.beans.property.ReadOnlyIntegerProperty currentCountPropertyThe 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 tostartTime, i.e., whenstopTimeor the end of media has been reached.- See Also:
-
cycleDuration
javafx.beans.property.ReadOnlyObjectProperty<javafx.util.Duration> cycleDurationPropertyThe amount of time between thestartTimeandstopTimeof this player. For the total duration of the MediaSource use theMediaPlayer.durationproperty.- See Also:
-
totalDuration
javafx.beans.property.ReadOnlyObjectProperty<javafx.util.Duration> totalDurationPropertyThe total amount of play time if allowed to play until finished. IfcycleCountis set toINDEFINITEthen 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>> onReadyPropertyEvent handler invoked when the status changes toREADY.- See Also:
-
onPlaying
javafx.beans.property.ObjectProperty<javafx.event.EventHandler<MediaPlayerEvent>> onPlayingPropertyEvent handler invoked when the status changes toPLAYING.- See Also:
-
onPaused
javafx.beans.property.ObjectProperty<javafx.event.EventHandler<MediaPlayerEvent>> onPausedPropertyEvent handler invoked when the status changes toPAUSED.- See Also:
-
onStopped
javafx.beans.property.ObjectProperty<javafx.event.EventHandler<MediaPlayerEvent>> onStoppedPropertyEvent handler invoked when the status changes toSTOPPED.- See Also:
-
onStalled
javafx.beans.property.ObjectProperty<javafx.event.EventHandler<MediaPlayerEvent>> onStalledPropertyEvent handler invoked when the status changes toSTALLED.- See Also:
-
onEndOfMedia
javafx.beans.property.ObjectProperty<javafx.event.EventHandler<MediaPlayerEvent>> onEndOfMediaPropertyEvent handler invoked when the end of media is reached naturally.- See Also:
-
onRepeat
javafx.beans.property.ObjectProperty<javafx.event.EventHandler<MediaPlayerEvent>> onRepeatPropertyEvent handler invoked when the playercurrentTimereachesstopTimeand will be repeating. This callback is made prior to seeking back tostartTime.- See Also:
-
onError
javafx.beans.property.ObjectProperty<javafx.event.EventHandler<MediaPlayerEvent>> onErrorPropertyEvent handler invoked when an error occurs.- See Also:
-
error
javafx.beans.property.ReadOnlyObjectProperty<MediaPlayerException> errorPropertyObservable property set to aMediaPlayerExceptionif an error occurs.- See Also:
-
-
Field Details
-
INDEFINITE
static final int INDEFINITEA value representing an effectively infinite number of playback cycles. WhencycleCountis set to this value, the player will replay theMediaSourceuntil stopped or paused.- See Also:
-
-
Method Details
-
create
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 stagemediaSource- the media source- Returns:
- a
MediaPlayerobject.
-
getMediaSource
MediaSource getMediaSource()Retrieves the current media source.- Returns:
MediaSourceobject
-
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 viaWebAPI.JSFileremotely.- Returns:
- the
mediaSourceproperty - See Also:
-
setAutoPlay
void setAutoPlay(boolean value) Sets theautoPlayproperty value.- Parameters:
value- whether to enable auto-playback
-
isAutoPlay
boolean isAutoPlay()Retrieves theautoPlayproperty 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 isfalse.- Returns:
- the
autoPlayproperty - 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
statusproperty - 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, aDuration.UNKNOWNvalue 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 isDuration.UNKNOWN, then this will likewise beDuration.UNKNOWN.- Returns:
- the duration of the media
- See Also:
-
getVolume
double getVolume()Retrieves the audio playback volume. The default value is1.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
volumeproperty - 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 oftrueindicates that audio is not being produced. The value of this property has no effect onvolume, i.e., if the audio is muted and then unmuted, audio playback will resume at the same audible level provided of course that thevolumeproperty has not been modified meanwhile. The default value isfalse.- Returns:
- the
muteproperty - 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 isDuration.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 of1.0plays the media at its normal (encoded) playback rate,2.0plays back at twice the normal rate, etc. The currently supported range of rates is[0.0, 8.0]. The default value is1.0.- Returns:
- the
rateproperty - 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, ifrateis set to 1.0 and the player is paused or stalled, thencurrentRatewill be zero.- Returns:
- the
currentRateproperty - 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: useseek(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 isDuration.ZERO.- Returns:
- the start time
-
setStartTime
void setStartTime(javafx.util.Duration value) Sets the start time. Its effect will be clamped to the range[. Invoking this method will have no effect if media duration isDuration.ZERO,stopTime)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 isDuration.ZERO.Constraints:
0 ≤ startTime <stopTime- Returns:
- the
startTimeproperty - See Also:
-
getStopTime
javafx.util.Duration getStopTime()Retrieves the stop time. The default value is. Note thatgetDuration()may have the valuedurationDuration.UNKNOWNif 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(. Invoking this method will have no effect if media duration isstartTime,Media.duration]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
stopTimeproperty - 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,. Invoking this method will have no effect if media duration isInteger.MAX_VALUE]Duration.INDEFINITE.- Parameters:
value- the cycle count
-
cycleCountProperty
javafx.beans.property.IntegerProperty cycleCountProperty()The number of times the media will be played. By default,cycleCountis set to1meaning the media will only be played once. SettingcycleCountto a value greater than 1 will cause the media to play the given number of times or until stopped. If set toINDEFINITE, playback will repeat until stop() or pause() is called.constraints:
cycleCount ≥ 1- Returns:
- the
cycleCountproperty - 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 tostartTime, i.e., whenstopTimeor the end of media has been reached.- Returns:
- the
currentCountproperty - 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 thestartTimeandstopTimeof this player. For the total duration of the MediaSource use theMediaPlayer.durationproperty.- Returns:
- the
cycleDurationproperty - 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. IfcycleCountis set toINDEFINITEthen 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
totalDurationproperty - See Also:
-
getOnReady
javafx.event.EventHandler<MediaPlayerEvent> getOnReady()Retrieves theMediaPlayer.Status.READYevent handler.- Returns:
- the event handler or
null.
-
setOnReady
Sets theMediaPlayer.Status.READYevent handler.- Parameters:
value- the event handler ornull.
-
onReadyProperty
javafx.beans.property.ObjectProperty<javafx.event.EventHandler<MediaPlayerEvent>> onReadyProperty()Event handler invoked when the status changes toREADY.- Returns:
- the
onReadyproperty - See Also:
-
getOnPlaying
javafx.event.EventHandler<MediaPlayerEvent> getOnPlaying()Retrieves theMediaPlayer.Status.PLAYINGevent handler.- Returns:
- the event handler or
null.
-
setOnPlaying
Sets theMediaPlayer.Status.PLAYINGevent handler.- Parameters:
value- the event handler ornull.
-
onPlayingProperty
javafx.beans.property.ObjectProperty<javafx.event.EventHandler<MediaPlayerEvent>> onPlayingProperty()Event handler invoked when the status changes toPLAYING.- Returns:
- the
onPlayingproperty - See Also:
-
getOnPaused
javafx.event.EventHandler<MediaPlayerEvent> getOnPaused()Retrieves theMediaPlayer.Status.PAUSEDevent handler.- Returns:
- the event handler or
null.
-
setOnPaused
Sets theMediaPlayer.Status.PAUSEDevent handler.- Parameters:
value- the event handler ornull.
-
onPausedProperty
javafx.beans.property.ObjectProperty<javafx.event.EventHandler<MediaPlayerEvent>> onPausedProperty()Event handler invoked when the status changes toPAUSED.- Returns:
- the
onPausedproperty - See Also:
-
getOnStopped
javafx.event.EventHandler<MediaPlayerEvent> getOnStopped()Retrieves theMediaPlayer.Status.STOPPEDevent handler.- Returns:
- the event handler or
null.
-
setOnStopped
Sets theMediaPlayer.Status.STOPPEDevent handler.- Parameters:
value- the event handler ornull.
-
onStoppedProperty
javafx.beans.property.ObjectProperty<javafx.event.EventHandler<MediaPlayerEvent>> onStoppedProperty()Event handler invoked when the status changes toSTOPPED.- Returns:
- the
onStoppedproperty - See Also:
-
getOnStalled
javafx.event.EventHandler<MediaPlayerEvent> getOnStalled()Retrieves theMediaPlayer.Status.STALLEDevent handler.- Returns:
- the event handler or
null.
-
setOnStalled
Sets theMediaPlayer.Status.STALLEDevent handler.- Parameters:
value- the event handler ornull.
-
onStalledProperty
javafx.beans.property.ObjectProperty<javafx.event.EventHandler<MediaPlayerEvent>> onStalledProperty()Event handler invoked when the status changes toSTALLED.- Returns:
- the
onStalledproperty - 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
Sets the event handler invoked when the end of media is reached naturally.- Parameters:
value- the event handler ornull.
-
onEndOfMediaProperty
javafx.beans.property.ObjectProperty<javafx.event.EventHandler<MediaPlayerEvent>> onEndOfMediaProperty()Event handler invoked when the end of media is reached naturally.- Returns:
- the
onEndOfMediaproperty - See Also:
-
getOnRepeat
javafx.event.EventHandler<MediaPlayerEvent> getOnRepeat()Retrieves the repeat event handler.- Returns:
- the event handler or
null.
-
setOnRepeat
Sets the repeat event handler.- Parameters:
value- the event handler ornull.
-
onRepeatProperty
javafx.beans.property.ObjectProperty<javafx.event.EventHandler<MediaPlayerEvent>> onRepeatProperty()Event handler invoked when the playercurrentTimereachesstopTimeand will be repeating. This callback is made prior to seeking back tostartTime.- Returns:
- the
onRepeatproperty - See Also:
-
getOnError
javafx.event.EventHandler<MediaPlayerEvent> getOnError()Retrieves the event handler for errors.- Returns:
- the event handler.
-
setOnError
Sets the event handler to be called when an error occurs.- Parameters:
value- the event handler ornull.
-
onErrorProperty
javafx.beans.property.ObjectProperty<javafx.event.EventHandler<MediaPlayerEvent>> onErrorProperty()Event handler invoked when an error occurs.- Returns:
- the
onErrorproperty - See Also:
-
getError
MediaPlayerException getError()Retrieve the value of theerrorproperty ornullif there is no error.- Returns:
- a
MediaPlayerExceptionornull.
-
errorProperty
javafx.beans.property.ReadOnlyObjectProperty<MediaPlayerException> errorProperty()Observable property set to aMediaPlayerExceptionif an error occurs.- Returns:
- the
errorproperty - See Also:
-
play
void play() -
pause
void pause()Pauses the player. Once the player is actually paused thestatuswill be set toMediaPlayer.Status.PAUSED. -
stop
void stop()Stops playing the media. This operation resets playback tostartTimeandcurrentCountto zero. Once the player is actually stopped, thestatuswill be set toMediaPlayer.Status.STOPPED. The only transitions out ofSTOPPEDstatus are toMediaPlayer.Status.PAUSEDandMediaPlayer.Status.PLAYINGwhich occur after invokingpause()orplay(), respectively. While stopped, the player will not respond to playback position changes requested byseek(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 isMediaPlayer.Status.STOPPEDor media duration isDuration.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 seekTime seek position nullno change Duration.UNKNOWNno change Duration.INDEFINITEstop time seekTime < start time start time seekTime > stop time stop time start time ≤ seekTime ≤ stop time seekTime - Parameters:
seekTime- the requested playback time
-