public final class Media extends Object
Media class represents a media resource. It is instantiated
 from the string form of a source URI. Information about the media such as
 duration, metadata, tracks, and video resolution may be obtained from a
 Media instance. The media information is obtained asynchronously
 and so not necessarily available immediately after instantiation of the class.
 All information should however be available if the instance has been
 associated with a MediaPlayer and that player has transitioned to
 MediaPlayer.Status.READY status. To be notified when metadata or
 Tracks are added, observers may be registered with the collections
 returned by getMetadata()and getTracks(), respectively.
 The same Media object may be shared among multiple
 MediaPlayer objects. Such a shared instance might manage a single
 copy of the source media data to be used by all players, or it might require a
 separate copy of the data for each player. The choice of implementation will
 not however have any effect on player behavior at the interface level.
- Since:
- JavaFX 2.0
- See Also:
- MediaPlayer,- MediaException
- 
Property SummaryProperties Type Property Description ReadOnlyObjectProperty<Duration>durationThe duration in seconds of the source media.ReadOnlyObjectProperty<MediaException>errorA property set to a MediaException value when an error occurs.ReadOnlyIntegerPropertyheightThe height in pixels of the source media.ObjectProperty<Runnable>onErrorEvent handler called when an error occurs.ReadOnlyIntegerPropertywidthThe width in pixels of the source media.
- 
Constructor Summary
- 
Method SummaryModifier and Type Method Description ReadOnlyObjectProperty<Duration>durationProperty()The duration in seconds of the source media.ReadOnlyObjectProperty<MediaException>errorProperty()A property set to a MediaException value when an error occurs.DurationgetDuration()Retrieve the duration in seconds of the media.MediaExceptiongetError()Return any error encountered in the media.intgetHeight()Retrieve the height in pixels of the media.ObservableMap<String,Duration>getMarkers()Retrieve the markers defined on thisMediainstance.ObservableMap<String,Object>getMetadata()Retrieve the metadata contained in this media source.RunnablegetOnError()Retrieve the error handler to be called if an error occurs.StringgetSource()Retrieve the source URI of the media.ObservableList<Track>getTracks()Retrieve the tracks contained in this media source.intgetWidth()Retrieve the width in pixels of the media.ReadOnlyIntegerPropertyheightProperty()The height in pixels of the source media.ObjectProperty<Runnable>onErrorProperty()Event handler called when an error occurs.voidsetOnError(Runnable value)Set the event handler to be called when an error occurs.ReadOnlyIntegerPropertywidthProperty()The width in pixels of the source media.
- 
Property Details- 
errorA property set to a MediaException value when an error occurs. Iferroris non-null, then the media could not be loaded and is not usable. IfonErroris non-null, it will be invoked when theerrorproperty is set.- See Also:
- getError()
 
- 
onErrorEvent handler called when an error occurs. This will happen if a malformed or invalid URL is passed to the constructor or there is a problem accessing the URL.- See Also:
- getOnError(),- setOnError(Runnable)
 
- 
widthThe width in pixels of the source media. This may be zero if the media has no width, e.g., when playing audio, or if the width is currently unknown which may occur with streaming media.- See Also:
- getWidth()
 
- 
heightThe height in pixels of the source media. This may be zero if the media has no height, e.g., when playing audio, or if the height is currently unknown which may occur with streaming media.- See Also:
- getHeight()
 
- 
durationThe duration in seconds of the source media. If the media duration is unknown then this property value will beDuration.UNKNOWN.- See Also:
- getDuration()
 
 
- 
- 
Constructor Details- 
MediaConstructs aMediainstance. This is the only way to specify the media source. The source must represent a validURIand is immutable. Only HTTP, HTTPS, FILE, and JARURLs are supported. If the provided URL is invalid then an exception will be thrown. If an asynchronous error occurs, theerrorproperty will be set. Listen to this property to be notified of any such errors.If the source uses a non-blocking protocol such as FILE, then any problems which can be detected immediately will cause a MediaExceptionto be thrown. Such problems include the media being inaccessible or in an unsupported format. If however a potentially blocking protocol such as HTTP is used, then the connection will be initialized asynchronously so that these sorts of errors will be signaled by setting theerrorproperty.Constraints: - The supplied URI must conform to RFC-2396 as required by java.net.URI.
- Only HTTP, HTTPS, FILE, and JAR URIs are supported.
 See java.net.URI for more information about URI formatting in general. JAR URL syntax is specified in java.net.JarURLConnection. - Parameters:
- source- The URI of the source media.
- Throws:
- NullPointerException- if the URI string is- null.
- IllegalArgumentException- if the URI string does not conform to RFC-2396 or, if appropriate, the Jar URL specification, or is in a non-compliant form which cannot be modified to a compliant form.
- IllegalArgumentException- if the URI string has a- nullscheme.
- UnsupportedOperationException- if the protocol specified for the source is not supported.
- MediaException- if the media source cannot be connected (type- MediaException.Type.MEDIA_INACCESSIBLE) or is not supported (type- MediaException.Type.MEDIA_UNSUPPORTED).
 
 
- 
- 
Method Details- 
getErrorReturn any error encountered in the media.- Returns:
- a MediaExceptionornullif there is no error.
 
- 
errorPropertyA property set to a MediaException value when an error occurs. Iferroris non-null, then the media could not be loaded and is not usable. IfonErroris non-null, it will be invoked when theerrorproperty is set.- See Also:
- getError()
 
- 
setOnErrorSet the event handler to be called when an error occurs.- Parameters:
- value- the error event handler.
 
- 
getOnErrorRetrieve the error handler to be called if an error occurs.- Returns:
- the error handler or nullif none is defined.
 
- 
onErrorPropertyEvent handler called when an error occurs. This will happen if a malformed or invalid URL is passed to the constructor or there is a problem accessing the URL.- See Also:
- getOnError(),- setOnError(Runnable)
 
- 
getMetadataRetrieve the metadata contained in this media source. If there are no metadata, the returnedObservableMapwill be empty.- Returns:
- the metadata contained in this media source.
 
- 
getWidthpublic final int getWidth()Retrieve the width in pixels of the media.- Returns:
- the media width or zero if the width is undefined or unknown.
 
- 
widthPropertyThe width in pixels of the source media. This may be zero if the media has no width, e.g., when playing audio, or if the width is currently unknown which may occur with streaming media.- See Also:
- getWidth()
 
- 
getHeightpublic final int getHeight()Retrieve the height in pixels of the media.- Returns:
- the media height or zero if the height is undefined or unknown.
 
- 
heightPropertyThe height in pixels of the source media. This may be zero if the media has no height, e.g., when playing audio, or if the height is currently unknown which may occur with streaming media.- See Also:
- getHeight()
 
- 
getDurationRetrieve the duration in seconds of the media.- Returns:
- the duration of the media, Duration.UNKNOWNif unknown orDuration.INDEFINITEfor live streams
 
- 
durationPropertyThe duration in seconds of the source media. If the media duration is unknown then this property value will beDuration.UNKNOWN.- See Also:
- getDuration()
 
- 
getTracksRetrieve the tracks contained in this media source. If there are no tracks, the returnedObservableListwill be empty.- Returns:
- the tracks contained in this media source.
 
- 
getMarkersRetrieve the markers defined on thisMediainstance. If there are no markers the returnedObservableMapwill be empty. Programmatic markers may be added by inserting entries in the returnedMap.- Returns:
- the markers defined on this media source.
 
- 
getSourceRetrieve the source URI of the media.- Returns:
- the media source URI as a String.
 
 
-