public final class MediaPlayer extends Object
MediaPlayer class provides the controls for playing media.
 It is used in combination with the Media and MediaView
 classes to display and control media playback. MediaPlayer does
 not contain any visual elements so must be used with the MediaView
 class to view any video track which may be present.
 MediaPlayer provides the pause(), play(),
 stop() and seek() controls as
 well as the rate and autoPlay
 properties which apply to all types of media. It also provides the
 balance, mute, and
 volume properties which control audio playback
 characteristics. Further control over audio quality may be attained via the
 AudioEqualizer associated with the player. Frequency descriptors of
 audio playback may be observed by registering an AudioSpectrumListener.
 Information about playback position, rate, and buffering may be obtained from
 the currentTime,
 currentRate, and
 bufferProgressTime
 properties, respectively. Media marker notifications are received by an event
 handler registered as the onMarker property.
For finite duration media, playback may be positioned at any point in time
 between 0.0 and the duration of the media. MediaPlayer
 refines this definition by adding the startTime and
 stopTime
 properties which in effect define a virtual media source with time position
 constrained to [startTime,stopTime]. Media playback
 commences at startTime and continues to stopTime.
 The interval defined by these two endpoints is termed a cycle with
 duration being the difference of the stop and start times. This cycle
 may be set to repeat a specific or indefinite number of times. The total
 duration of media playback is then 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 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 to be repeated or not.
 A zero-relative index of which cycle is presently being played is maintained
 by currentCount.
 
The operation of a MediaPlayer is inherently asynchronous.
 A player is not prepared to respond to commands quasi-immediately until
 its status has transitioned to MediaPlayer.Status.READY, which in
 effect generally occurs when media pre-roll completes. Some requests made of
 a player prior to its status being READY will however take
 effect when that status is entered. These include invoking play()
 without an intervening invocation of pause() or stop()
 before the READY transition, as well as setting any of the
 autoPlay, balance,
 mute, rate,
 startTime, stopTime, and
 volume properties.
The status
 property may be monitored to make the application aware of player status
 changes, and callback functions may be registered via properties such as
 onReady if an action should be taken when a particular status is
 entered. There are also error and onError properties which
 respectively enable monitoring when an error occurs and taking a specified
 action in response thereto.
The same MediaPlayer object may be shared among multiple
 MediaViews. This will not affect the player itself. In
 particular, the property settings of the view will not have any effect on
 media playback.
- 
Property SummaryProperties Type Property Description DoublePropertyaudioSpectrumIntervalThe interval between spectrum updates in seconds.ObjectProperty<AudioSpectrumListener>audioSpectrumListenerA listener for audio spectrum updates.IntegerPropertyaudioSpectrumNumBandsThe number of bands in the audio spectrum.IntegerPropertyaudioSpectrumThresholdThe sensitivity threshold in decibels; must be non-positive.BooleanPropertyautoPlayWhether playing should start as soon as possible.DoublePropertybalanceThe balance, or left-right setting, of the audio output.ReadOnlyObjectProperty<Duration>bufferProgressTimeThe current buffer position indicating how much media can be played without stalling theMediaPlayer.ReadOnlyIntegerPropertycurrentCountThe number of completed playback cycles.ReadOnlyDoublePropertycurrentRateThe current rate of playback regardless of settings.ReadOnlyObjectProperty<Duration>currentTimeThe current media playback time.IntegerPropertycycleCountThe number of times the media will be played.ReadOnlyObjectProperty<Duration>cycleDurationReadOnlyObjectProperty<MediaException>errorObservable property set to aMediaExceptionif an error occurs.BooleanPropertymuteWhether the player audio is muted.ObjectProperty<Runnable>onEndOfMediaEvent handler invoked when the playercurrentTimereachesstopTime.ObjectProperty<Runnable>onErrorEvent handler invoked when an error occurs.ObjectProperty<Runnable>onHaltedEvent handler invoked when the status changes toHALTED.ObjectProperty<EventHandler<MediaMarkerEvent>>onMarkerEvent handler invoked when the playercurrentTimereaches a media marker.ObjectProperty<Runnable>onPausedEvent handler invoked when the status changes toPAUSED.ObjectProperty<Runnable>onPlayingEvent handler invoked when the status changes toPLAYING.ObjectProperty<Runnable>onReadyEvent handler invoked when the status changes toREADY.ObjectProperty<Runnable>onRepeatEvent handler invoked when the playercurrentTimereachesstopTimeand will be repeating.ObjectProperty<Runnable>onStalledEvent handler invoked when the status changes toSTALLED.ObjectProperty<Runnable>onStoppedEvent handler invoked when the status changes toSTOPPED.DoublePropertyrateThe rate at which the media should be played.ObjectProperty<Duration>startTimeThe time offset where media should start playing, or restart from when repeating.ReadOnlyObjectProperty<MediaPlayer.Status>statusThe current state of the MediaPlayer.ObjectProperty<Duration>stopTimeThe time offset where media should stop playing or restart when repeating.ReadOnlyObjectProperty<Duration>totalDurationThe total amount of play time if allowed to play until finished.DoublePropertyvolumeThe volume at which the media should be played.
- 
Nested Class SummaryNested Classes Modifier and Type Class Description static classMediaPlayer.StatusEnumeration describing the different status values of aMediaPlayer.
- 
Field SummaryFields Modifier and Type Field Description static intINDEFINITEA value representing an effectively infinite number of playback cycles.
- 
Constructor SummaryConstructors Constructor Description MediaPlayer(Media media)Create a player for a specific media.
- 
Method SummaryModifier and Type Method Description DoublePropertyaudioSpectrumIntervalProperty()The interval between spectrum updates in seconds.ObjectProperty<AudioSpectrumListener>audioSpectrumListenerProperty()A listener for audio spectrum updates.IntegerPropertyaudioSpectrumNumBandsProperty()The number of bands in the audio spectrum.IntegerPropertyaudioSpectrumThresholdProperty()The sensitivity threshold in decibels; must be non-positive.BooleanPropertyautoPlayProperty()Whether playing should start as soon as possible.DoublePropertybalanceProperty()The balance, or left-right setting, of the audio output.ReadOnlyObjectProperty<Duration>bufferProgressTimeProperty()The current buffer position indicating how much media can be played without stalling theMediaPlayer.ReadOnlyIntegerPropertycurrentCountProperty()The number of completed playback cycles.ReadOnlyDoublePropertycurrentRateProperty()The current rate of playback regardless of settings.ReadOnlyObjectProperty<Duration>currentTimeProperty()The current media playback time.IntegerPropertycycleCountProperty()The number of times the media will be played.ReadOnlyObjectProperty<Duration>cycleDurationProperty()voiddispose()Free all resources associated with player.ReadOnlyObjectProperty<MediaException>errorProperty()Observable property set to aMediaExceptionif an error occurs.AudioEqualizergetAudioEqualizer()Retrieve theAudioEqualizerassociated with this player.doublegetAudioSpectrumInterval()Retrieves the value of the audio spectrum notification interval in seconds.AudioSpectrumListenergetAudioSpectrumListener()Retrieves the listener of the audio spectrum.intgetAudioSpectrumNumBands()Retrieves the number of bands in the audio spectrum.intgetAudioSpectrumThreshold()Retrieves the audio spectrum threshold in decibels.doublegetBalance()Retrieves the audio balance.DurationgetBufferProgressTime()Retrieves thebufferProgressTimevalue.intgetCurrentCount()Retrieves the index of the current cycle.doublegetCurrentRate()Retrieves the current playback rate.DurationgetCurrentTime()Retrieves the current media time.intgetCycleCount()Retrieves the cycle count.DurationgetCycleDuration()Retrieves the cycle duration in seconds.MediaExceptiongetError()Retrieve the value of theerrorproperty ornullif there is no error.MediagetMedia()Retrieves theMediainstance being played.RunnablegetOnEndOfMedia()Retrieves the end of media event handler.RunnablegetOnError()Retrieves the event handler for errors.RunnablegetOnHalted()Retrieves theMediaPlayer.Status.HALTEDevent handler.EventHandler<MediaMarkerEvent>getOnMarker()Retrieves the marker event handler.RunnablegetOnPaused()Retrieves theMediaPlayer.Status.PAUSEDevent handler.RunnablegetOnPlaying()Retrieves theMediaPlayer.Status.PLAYINGevent handler.RunnablegetOnReady()Retrieves theMediaPlayer.Status.READYevent handler.RunnablegetOnRepeat()Retrieves the repeat event handler.RunnablegetOnStalled()Retrieves theMediaPlayer.Status.STALLEDevent handler.RunnablegetOnStopped()Retrieves theMediaPlayer.Status.STOPPEDevent handler.doublegetRate()Retrieves the playback rate.DurationgetStartTime()Retrieves the start time.MediaPlayer.StatusgetStatus()Retrieves the current player status.DurationgetStopTime()Retrieves the stop time.DurationgetTotalDuration()Retrieves the total playback duration including all cycles (repetitions).doublegetVolume()Retrieves the audio playback volume.booleanisAutoPlay()Retrieves theautoPlayproperty value.booleanisMute()Retrieves themuteProperty()value.BooleanPropertymuteProperty()Whether the player audio is muted.ObjectProperty<Runnable>onEndOfMediaProperty()Event handler invoked when the playercurrentTimereachesstopTime.ObjectProperty<Runnable>onErrorProperty()Event handler invoked when an error occurs.ObjectProperty<Runnable>onHaltedProperty()Event handler invoked when the status changes toHALTED.ObjectProperty<EventHandler<MediaMarkerEvent>>onMarkerProperty()Event handler invoked when the playercurrentTimereaches a media marker.ObjectProperty<Runnable>onPausedProperty()Event handler invoked when the status changes toPAUSED.ObjectProperty<Runnable>onPlayingProperty()Event handler invoked when the status changes toPLAYING.ObjectProperty<Runnable>onReadyProperty()Event handler invoked when the status changes toREADY.ObjectProperty<Runnable>onRepeatProperty()Event handler invoked when the playercurrentTimereachesstopTimeand will be repeating.ObjectProperty<Runnable>onStalledProperty()Event handler invoked when the status changes toSTALLED.ObjectProperty<Runnable>onStoppedProperty()Event handler invoked when the status changes toSTOPPED.voidpause()Pauses the player.voidplay()Starts playing the media.DoublePropertyrateProperty()The rate at which the media should be played.voidseek(Duration seekTime)Seeks the player to a new playback time.voidsetAudioSpectrumInterval(double value)Sets the value of the audio spectrum notification interval in seconds.voidsetAudioSpectrumListener(AudioSpectrumListener listener)Sets the listener of the audio spectrum.voidsetAudioSpectrumNumBands(int value)Sets the number of bands in the audio spectrum.voidsetAudioSpectrumThreshold(int value)Sets the audio spectrum threshold in decibels.voidsetAutoPlay(boolean value)Sets theautoPlayproperty value.voidsetBalance(double value)Sets the audio balance.voidsetCycleCount(int value)Sets the cycle count.voidsetMute(boolean value)Sets the value ofmuteProperty().voidsetOnEndOfMedia(Runnable value)Sets the end of media event handler.voidsetOnError(Runnable value)Sets the event handler to be called when an error occurs.voidsetOnHalted(Runnable value)Sets theMediaPlayer.Status.HALTEDevent handler.voidsetOnMarker(EventHandler<MediaMarkerEvent> onMarker)Sets the marker event handler.voidsetOnPaused(Runnable value)Sets theMediaPlayer.Status.PAUSEDevent handler.voidsetOnPlaying(Runnable value)Sets theMediaPlayer.Status.PLAYINGevent handler.voidsetOnReady(Runnable value)Sets theMediaPlayer.Status.READYevent handler.voidsetOnRepeat(Runnable value)Sets the repeat event handler.voidsetOnStalled(Runnable value)Sets theMediaPlayer.Status.STALLEDevent handler.voidsetOnStopped(Runnable value)Sets theMediaPlayer.Status.STOPPEDevent handler.voidsetRate(double value)Sets the playback rate to the supplied value.voidsetStartTime(Duration value)Sets the start time.voidsetStopTime(Duration value)Sets the stop time.voidsetVolume(double value)Sets the audio playback volume.ObjectProperty<Duration>startTimeProperty()The time offset where media should start playing, or restart from when repeating.ReadOnlyObjectProperty<MediaPlayer.Status>statusProperty()The current state of the MediaPlayer.voidstop()Stops playing the media.ObjectProperty<Duration>stopTimeProperty()The time offset where media should stop playing or restart when repeating.ReadOnlyObjectProperty<Duration>totalDurationProperty()The total amount of play time if allowed to play until finished.DoublePropertyvolumeProperty()The volume at which the media should be played.
- 
Property Details- 
errorObservable property set to aMediaExceptionif an error occurs.- See Also:
- getError()
 
- 
onErrorEvent handler invoked when an error occurs.- See Also:
- getOnError(),- setOnError(Runnable)
 
- 
autoPlayWhether 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:
- isAutoPlay(),- setAutoPlay(boolean)
 
- 
rateThe 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:
- getRate(),- setRate(double)
 
- 
currentRateThe 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:
- getCurrentRate()
 
- 
volumeThe volume at which the media should be played. The range of effective values is[0.0 1.0]where0.0is inaudible and1.0is full volume, which is the default.- See Also:
- getVolume(),- setVolume(double)
 
- 
balanceThe balance, or left-right setting, of the audio output. The range of effective values is[-1.0, 1.0]with-1.0being full left,0.0center, and1.0full right. The default value is0.0.- See Also:
- getBalance(),- setBalance(double)
 
- 
startTimeThe 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:
- getStartTime(),- setStartTime(Duration)
 
- 
stopTimeThe time offset where media should stop playing or restart when repeating. The default value isgetMedia().getDuration()Constraints: startTime< stopTime ≤Media.duration- See Also:
- getStopTime(),- setStopTime(Duration)
 
- 
cycleDurationThe amount of time between thestartTimeandstopTimeof this player. For the total duration of the Media use theMedia.durationproperty.- See Also:
- getCycleDuration()
 
- 
totalDurationThe total amount of play time if allowed to play until finished. IfcycleCountis set toINDEFINITEthen this will also be INDEFINITE. If the Media duration is UNKNOWN, then this will likewise be UNKNOWN. Otherwise, total duration will be the product of cycleDuration and cycleCount.- See Also:
- getTotalDuration()
 
- 
currentTimeThe current media playback time. This property is read-only: useseek(javafx.util.Duration)to change playback to a different stream position.- See Also:
- getCurrentTime()
 
- 
statusThe current state of the MediaPlayer.- See Also:
- getStatus()
 
- 
bufferProgressTimeThe current buffer position indicating how much media can be played without stalling theMediaPlayer. This is applicable to buffered streams such as those reading from network connections as opposed for example to local files.Seeking to a position beyond bufferProgressTimemight cause a slight pause in playback until an amount of data sufficient to permit playback resumption has been buffered.- See Also:
- getBufferProgressTime()
 
- 
cycleCountThe 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:
- getCycleCount(),- setCycleCount(int)
 
- 
currentCountThe 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:
- getCurrentCount()
 
- 
muteWhether 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 un-muted, 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:
- isMute(),- setMute(boolean)
 
- 
onMarkerEvent handler invoked when the playercurrentTimereaches a media marker.- See Also:
- getOnMarker(),- setOnMarker(EventHandler)
 
- 
onEndOfMediaEvent handler invoked when the playercurrentTimereachesstopTime.- See Also:
- getOnEndOfMedia(),- setOnEndOfMedia(Runnable)
 
- 
onReadyEvent handler invoked when the status changes toREADY.- See Also:
- getOnReady(),- setOnReady(Runnable)
 
- 
onPlayingEvent handler invoked when the status changes toPLAYING.- See Also:
- getOnPlaying(),- setOnPlaying(Runnable)
 
- 
onPausedEvent handler invoked when the status changes toPAUSED.- See Also:
- getOnPaused(),- setOnPaused(Runnable)
 
- 
onStoppedEvent handler invoked when the status changes toSTOPPED.- See Also:
- getOnStopped(),- setOnStopped(Runnable)
 
- 
onHaltedEvent handler invoked when the status changes toHALTED.- See Also:
- getOnHalted(),- setOnHalted(Runnable)
 
- 
onRepeatEvent handler invoked when the playercurrentTimereachesstopTimeand will be repeating. This callback is made prior to seeking back tostartTime.- See Also:
- getOnRepeat(),- setOnRepeat(Runnable)
 
- 
onStalledEvent handler invoked when the status changes toSTALLED.- See Also:
- getOnStalled(),- setOnStalled(Runnable)
 
- 
audioSpectrumNumBandsThe number of bands in the audio spectrum. The default value is 128; minimum is 2. The frequency range of the audio signal will be divided into the specified number of frequency bins. For example, a typical digital music signal has a frequency range of[0.0, 22050]Hz. If the number of spectral bands were in this case set to 10, the width of each frequency bin in the spectrum would be2205Hz with the lower bound of the lowest frequency bin equal to0.0.
- 
audioSpectrumIntervalThe interval between spectrum updates in seconds. The default is0.1seconds.
- 
audioSpectrumThresholdThe sensitivity threshold in decibels; must be non-positive. Values below this threshold with respect to the peak frequency in the given spectral band will be set to the value of the threshold. The default value is -60 dB.
- 
audioSpectrumListenerA listener for audio spectrum updates. When the listener is registered, audio spectrum computation is enabled; upon removing the listener, computation is disabled. Only a single listener may be registered, so if multiple observers are required, events must be forwarded.An AudioSpectrumListenermay be useful for example to plot the frequency spectrum of the audio being played or to generate waveforms for a music visualizer.
 
- 
- 
Field Details- 
INDEFINITEpublic static final int INDEFINITEA value representing an effectively infinite number of playback cycles. WhencycleCountis set to this value, the player will replay theMediauntil stopped or paused.- See Also:
- Constant Field Values
 
 
- 
- 
Constructor Details- 
MediaPlayerCreate a player for a specific media. This is the only way to associate aMediaobject with aMediaPlayer: once the player is created it cannot be changed. Errors which occur synchronously within the constructor will cause exceptions to be thrown. Errors which occur asynchronously will cause theerrorproperty to be set and consequently anyonErrorcallback to be invoked.When created, the statusof the player will beMediaPlayer.Status.UNKNOWN. Once thestatushas transitioned toMediaPlayer.Status.READYthe player will be in a usable condition. The amount of time between player creation and its enteringREADYstatus may vary depending, for example, on whether the media is being read over a network connection or from a local file system.- Parameters:
- media- The media to play.
- Throws:
- NullPointerException- if media is- null.
- MediaException- if any synchronous errors occur within the constructor.
 
 
- 
- 
Method Details- 
getAudioEqualizerRetrieve theAudioEqualizerassociated with this player.- Returns:
- the AudioEqualizerornullif player is disposed.
 
- 
getErrorRetrieve the value of theerrorproperty ornullif there is no error.- Returns:
- a MediaExceptionornull.
 
- 
errorPropertyObservable property set to aMediaExceptionif an error occurs.- See Also:
- getError()
 
- 
setOnErrorSets the event handler to be called when an error occurs.- Parameters:
- value- the event handler or- null.
 
- 
getOnErrorRetrieves the event handler for errors.- Returns:
- the event handler.
 
- 
onErrorPropertyEvent handler invoked when an error occurs.- See Also:
- getOnError(),- setOnError(Runnable)
 
- 
getMediaRetrieves theMediainstance being played.- Returns:
- the Mediaobject.
 
- 
setAutoPlaypublic final void setAutoPlay(boolean value)Sets theautoPlayproperty value.- Parameters:
- value- whether to enable auto-playback
 
- 
isAutoPlaypublic final boolean isAutoPlay()Retrieves theautoPlayproperty value.- Returns:
- the value.
 
- 
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:
- isAutoPlay(),- setAutoPlay(boolean)
 
- 
playpublic void play()Starts playing the media. If previously paused, then playback resumes where it was paused. If playback was stopped, playback starts from thestartTime. When playing actually starts thestatuswill be set toMediaPlayer.Status.PLAYING.
- 
pausepublic void pause()Pauses the player. Once the player is actually paused thestatuswill be set toMediaPlayer.Status.PAUSED.
- 
stoppublic void stop()Stops playing the media. This operation resets playback tostartTime, and resetscurrentCountto 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(javafx.util.Duration).
- 
setRatepublic final 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
 
- 
getRatepublic final double getRate()Retrieves the playback rate.- Returns:
- the playback rate
 
- 
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:
- getRate(),- setRate(double)
 
- 
getCurrentRatepublic final double getCurrentRate()Retrieves the current playback rate.- Returns:
- the current rate
 
- 
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:
- getCurrentRate()
 
- 
setVolumepublic final 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
 
- 
getVolumepublic final double getVolume()Retrieves the audio playback volume. The default value is1.0.- Returns:
- the audio volume
 
- 
volumePropertyThe volume at which the media should be played. The range of effective values is[0.0 1.0]where0.0is inaudible and1.0is full volume, which is the default.- See Also:
- getVolume(),- setVolume(double)
 
- 
setBalancepublic final void setBalance(double value)Sets the audio balance. Its effect will be clamped to the range[-1.0, 1.0].- Parameters:
- value- the balance
 
- 
getBalancepublic final double getBalance()Retrieves the audio balance.- Returns:
- the audio balance
 
- 
balancePropertyThe balance, or left-right setting, of the audio output. The range of effective values is[-1.0, 1.0]with-1.0being full left,0.0center, and1.0full right. The default value is0.0.- See Also:
- getBalance(),- setBalance(double)
 
- 
setStartTimeSets 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
 
- 
getStartTimeRetrieves the start time. The default value isDuration.ZERO.- Returns:
- the start time
 
- 
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:
- getStartTime(),- setStartTime(Duration)
 
- 
setStopTimeSets 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
 
- 
getStopTimeRetrieves the stop time. The default value isgetMedia().getDuration()Media.durationDuration.UNKNOWNif media initialization is not complete.- Returns:
- the stop time
 
- 
stopTimePropertyThe time offset where media should stop playing or restart when repeating. The default value isgetMedia().getDuration()Constraints: startTime< stopTime ≤Media.duration- See Also:
- getStopTime(),- setStopTime(Duration)
 
- 
getCycleDurationRetrieves the cycle duration in seconds.- Returns:
- the cycle duration
 
- 
cycleDurationPropertyThe amount of time between thestartTimeandstopTimeof this player. For the total duration of the Media use theMedia.durationproperty.- See Also:
- getCycleDuration()
 
- 
getTotalDurationRetrieves the total playback duration including all cycles (repetitions).- Returns:
- the total playback duration
 
- 
totalDurationPropertyThe total amount of play time if allowed to play until finished. IfcycleCountis set toINDEFINITEthen this will also be INDEFINITE. If the Media duration is UNKNOWN, then this will likewise be UNKNOWN. Otherwise, total duration will be the product of cycleDuration and cycleCount.- See Also:
- getTotalDuration()
 
- 
getCurrentTimeRetrieves the current media time.- Returns:
- the current media time
 
- 
currentTimePropertyThe current media playback time. This property is read-only: useseek(javafx.util.Duration)to change playback to a different stream position.- See Also:
- getCurrentTime()
 
- 
seekSeeks 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
 
- 
getStatusRetrieves the current player status.- Returns:
- the playback status
 
- 
statusPropertyThe current state of the MediaPlayer.- See Also:
- getStatus()
 
- 
getBufferProgressTimeRetrieves thebufferProgressTimevalue.- Returns:
- the buffer progress time
 
- 
bufferProgressTimePropertyThe current buffer position indicating how much media can be played without stalling theMediaPlayer. This is applicable to buffered streams such as those reading from network connections as opposed for example to local files.Seeking to a position beyond bufferProgressTimemight cause a slight pause in playback until an amount of data sufficient to permit playback resumption has been buffered.- See Also:
- getBufferProgressTime()
 
- 
setCycleCountpublic final 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
 
- 
getCycleCountpublic final int getCycleCount()Retrieves the cycle count.- Returns:
- the cycle count.
 
- 
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:
- getCycleCount(),- setCycleCount(int)
 
- 
getCurrentCountpublic final int getCurrentCount()Retrieves the index of the current cycle.- Returns:
- the current cycle index
 
- 
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:
- getCurrentCount()
 
- 
setMutepublic final void setMute(boolean value)Sets the value ofmuteProperty().- Parameters:
- value- the- mutesetting
 
- 
isMutepublic final boolean isMute()Retrieves themuteProperty()value.- Returns:
- the mute setting
 
- 
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 un-muted, 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:
- isMute(),- setMute(boolean)
 
- 
setOnMarkerSets the marker event handler.- Parameters:
- onMarker- the marker event handler.
 
- 
getOnMarkerRetrieves the marker event handler.- Returns:
- the marker event handler.
 
- 
onMarkerPropertyEvent handler invoked when the playercurrentTimereaches a media marker.- See Also:
- getOnMarker(),- setOnMarker(EventHandler)
 
- 
setOnEndOfMediaSets the end of media event handler.- Parameters:
- value- the event handler or- null.
 
- 
getOnEndOfMediaRetrieves the end of media event handler.- Returns:
- the event handler or null.
 
- 
onEndOfMediaPropertyEvent handler invoked when the playercurrentTimereachesstopTime.- See Also:
- getOnEndOfMedia(),- setOnEndOfMedia(Runnable)
 
- 
setOnReadySets theMediaPlayer.Status.READYevent handler.- Parameters:
- value- the event handler or- null.
 
- 
getOnReadyRetrieves theMediaPlayer.Status.READYevent handler.- Returns:
- the event handler or null.
 
- 
onReadyPropertyEvent handler invoked when the status changes toREADY.- See Also:
- getOnReady(),- setOnReady(Runnable)
 
- 
setOnPlayingSets theMediaPlayer.Status.PLAYINGevent handler.- Parameters:
- value- the event handler or- null.
 
- 
getOnPlayingRetrieves theMediaPlayer.Status.PLAYINGevent handler.- Returns:
- the event handler or null.
 
- 
onPlayingPropertyEvent handler invoked when the status changes toPLAYING.- See Also:
- getOnPlaying(),- setOnPlaying(Runnable)
 
- 
setOnPausedSets theMediaPlayer.Status.PAUSEDevent handler.- Parameters:
- value- the event handler or- null.
 
- 
getOnPausedRetrieves theMediaPlayer.Status.PAUSEDevent handler.- Returns:
- the event handler or null.
 
- 
onPausedPropertyEvent handler invoked when the status changes toPAUSED.- See Also:
- getOnPaused(),- setOnPaused(Runnable)
 
- 
setOnStoppedSets theMediaPlayer.Status.STOPPEDevent handler.- Parameters:
- value- the event handler or- null.
 
- 
getOnStoppedRetrieves theMediaPlayer.Status.STOPPEDevent handler.- Returns:
- the event handler or null.
 
- 
onStoppedPropertyEvent handler invoked when the status changes toSTOPPED.- See Also:
- getOnStopped(),- setOnStopped(Runnable)
 
- 
setOnHaltedSets theMediaPlayer.Status.HALTEDevent handler.- Parameters:
- value- the event handler or- null.
 
- 
getOnHaltedRetrieves theMediaPlayer.Status.HALTEDevent handler.- Returns:
- the event handler or null.
 
- 
onHaltedPropertyEvent handler invoked when the status changes toHALTED.- See Also:
- getOnHalted(),- setOnHalted(Runnable)
 
- 
setOnRepeatSets the repeat event handler.- Parameters:
- value- the event handler or- null.
 
- 
getOnRepeatRetrieves the repeat event handler.- Returns:
- the event handler or null.
 
- 
onRepeatPropertyEvent handler invoked when the playercurrentTimereachesstopTimeand will be repeating. This callback is made prior to seeking back tostartTime.- See Also:
- getOnRepeat(),- setOnRepeat(Runnable)
 
- 
setOnStalledSets theMediaPlayer.Status.STALLEDevent handler.- Parameters:
- value- the event handler or- null.
 
- 
getOnStalledRetrieves theMediaPlayer.Status.STALLEDevent handler.- Returns:
- the event handler or null.
 
- 
onStalledPropertyEvent handler invoked when the status changes toSTALLED.- See Also:
- getOnStalled(),- setOnStalled(Runnable)
 
- 
setAudioSpectrumNumBandspublic final void setAudioSpectrumNumBands(int value)Sets the number of bands in the audio spectrum.- Parameters:
- value- the number of spectral bands;- valuemust be ≥ 2
 
- 
getAudioSpectrumNumBandspublic final int getAudioSpectrumNumBands()Retrieves the number of bands in the audio spectrum.- Returns:
- the number of spectral bands.
 
- 
audioSpectrumNumBandsPropertyThe number of bands in the audio spectrum. The default value is 128; minimum is 2. The frequency range of the audio signal will be divided into the specified number of frequency bins. For example, a typical digital music signal has a frequency range of[0.0, 22050]Hz. If the number of spectral bands were in this case set to 10, the width of each frequency bin in the spectrum would be2205Hz with the lower bound of the lowest frequency bin equal to0.0.
- 
setAudioSpectrumIntervalpublic final void setAudioSpectrumInterval(double value)Sets the value of the audio spectrum notification interval in seconds.- Parameters:
- value- a positive value specifying the spectral update interval
 
- 
getAudioSpectrumIntervalpublic final double getAudioSpectrumInterval()Retrieves the value of the audio spectrum notification interval in seconds.- Returns:
- the spectral update interval
 
- 
audioSpectrumIntervalPropertyThe interval between spectrum updates in seconds. The default is0.1seconds.
- 
setAudioSpectrumThresholdpublic final void setAudioSpectrumThreshold(int value)Sets the audio spectrum threshold in decibels.- Parameters:
- value- the spectral threshold in dB; must be ≤- 0.
 
- 
getAudioSpectrumThresholdpublic final int getAudioSpectrumThreshold()Retrieves the audio spectrum threshold in decibels.- Returns:
- the spectral threshold in dB
 
- 
audioSpectrumThresholdPropertyThe sensitivity threshold in decibels; must be non-positive. Values below this threshold with respect to the peak frequency in the given spectral band will be set to the value of the threshold. The default value is -60 dB.
- 
setAudioSpectrumListenerSets the listener of the audio spectrum.- Parameters:
- listener- the spectral listener or- null.
 
- 
getAudioSpectrumListenerRetrieves the listener of the audio spectrum.- Returns:
- the spectral listener or null
 
- 
audioSpectrumListenerPropertyA listener for audio spectrum updates. When the listener is registered, audio spectrum computation is enabled; upon removing the listener, computation is disabled. Only a single listener may be registered, so if multiple observers are required, events must be forwarded.An AudioSpectrumListenermay be useful for example to plot the frequency spectrum of the audio being played or to generate waveforms for a music visualizer.
- 
disposepublic void dispose()Free all resources associated with player. Player SHOULD NOT be used after this function is called. Player will transition toMediaPlayer.Status.DISPOSEDafter this method is done. This method can be called anytime regardless of current player status.- Since:
- JavaFX 8.0
 
 
-