Top Description Inners Fields Constructors Methods
javafx.scene.media

public final Class Media

extends Object
Class Inheritance
Imports
com.sun.media.jfxmedia.MetadataParser, java.io.ByteArrayInputStream, .IOException, .FileNotFoundException, java.net.URI, .URISyntaxException, java.util.HashMap, .List, .Map, javafx.application.Platform, javafx.beans.NamedArg, javafx.beans.property.ObjectProperty, .ObjectPropertyBase, .ReadOnlyIntegerProperty, .ReadOnlyIntegerWrapper, .ReadOnlyObjectProperty, .ReadOnlyObjectWrapper, javafx.collections.FXCollections, .ObservableList, .ObservableMap, javafx.scene.image.Image, javafx.util.Duration, com.sun.media.jfxmedia.locator.Locator, com.sun.media.jfxmedia.events.MetadataListener

The 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

Nested and Inner Type Summary

Modifier and TypeClass and Description
private class
private class

Field Summary

Modifier and TypeField and Description
private ReadOnlyObjectWrapper<Duration>
duration

The duration in seconds of the source media.

private ReadOnlyObjectWrapper<MediaException>
error

A property set to a MediaException value when an error occurs.

private ReadOnlyIntegerWrapper
height

The height in pixels of the source media.

private final Locator
jfxLocator

Locator used by the jfxmedia player, MediaPlayer needs access to this

private MetadataParser
private ObservableMap<String, Duration>
markers

The markers defined on this media source.

private ObservableMap<String, Object>
metadata

An ObservableMap of metadata which can contain information about the media.

private final ObservableMap<String, Object>
private MetadataListener
private ObjectProperty<Runnable>
onError

Event handler called when an error occurs.

private final String
source

The source URI of the media;

private ObservableList<Track>
tracks

An ObservableList of tracks contained in this media object.

private final ObservableList<Track>
private ReadOnlyIntegerWrapper
width

The width in pixels of the source media.

Constructor Summary

AccessConstructor and Description
public
Media(String
The URI of the source media.
source
)

Constructs a Media instance.

Method Summary

Modifier and TypeMethod and Description
pack-priv void
pack-priv void
public ReadOnlyObjectProperty<Duration>
private ReadOnlyObjectWrapper<Duration>
public ReadOnlyObjectProperty<MediaException>
private ReadOnlyObjectWrapper<MediaException>
public final Duration

Returns:

the duration of the media, Duration#UNKNOWN if unknown or Duration#INDEFINITE for live streams
getDuration
()

Retrieve the duration in seconds of the media.

public final MediaException

Returns:

a MediaException or null if there is no error.
getError
()

Return any error encountered in the media.

public final int

Returns:

the media height or zero if the height is undefined or unknown.
getHeight
()

Retrieve the height in pixels of the media.

public final ObservableMap<String, Duration>

Returns:

the markers defined on this media source.
getMarkers
()

Retrieve the markers defined on this Media instance.

public final ObservableMap<String, Object>

Returns:

the metadata contained in this media source.
getMetadata
()

Retrieve the metadata contained in this media source.

public final Runnable

Returns:

the error handler or null if none is defined.
getOnError
()

Retrieve the error handler to be called if an error occurs.

public String

Returns:

the media source URI as a String.
getSource
()

Retrieve the source URI of the media.

public final ObservableList<Track>

Returns:

the tracks contained in this media source.
getTracks
()

Retrieve the tracks contained in this media source.

private Track
getTrackWithID(long trackID)

public final int

Returns:

the media width or zero if the width is undefined or unknown.
getWidth
()

Retrieve the width in pixels of the media.

public ReadOnlyIntegerProperty
private ReadOnlyIntegerWrapper
public ObjectProperty<Runnable>
pack-priv Locator
private void
pack-priv final void
private void
pack-priv final void
setHeight(int value)

public final void
setOnError(Runnable
the error event handler.
value
)

Set the event handler to be called when an error occurs.

pack-priv final void
setWidth(int value)

private synchronized void
public ReadOnlyIntegerProperty
private ReadOnlyIntegerWrapper
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

durationback to summary
private ReadOnlyObjectWrapper<Duration> duration

The duration in seconds of the source media. If the media duration is unknown then this property value will be Duration#UNKNOWN.

errorback to summary
private ReadOnlyObjectWrapper<MediaException> error

A property set to a MediaException value when an error occurs. If error is non-null, then the media could not be loaded and is not usable. If onError is non-null, it will be invoked when the error property is set.

See Also
MediaException
heightback to summary
private ReadOnlyIntegerWrapper height

The 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
width
jfxLocatorback to summary
private final Locator jfxLocator

Locator used by the jfxmedia player, MediaPlayer needs access to this

jfxParserback to summary
private MetadataParser jfxParser
markersback to summary
private ObservableMap<String, Duration> markers

The markers defined on this media source. A marker is defined to be a mapping from a name to a point in time between the beginning and end of the media.

metadataback to summary
private ObservableMap<String, Object> metadata

An ObservableMap of metadata which can contain information about the media. Metadata entries use Strings for keys and contain Object values. This map is unmodifiable: its contents or stored values cannot be changed.

metadataBackingback to summary
private final ObservableMap<String, Object> metadataBacking
metadataListenerback to summary
private MetadataListener metadataListener
onErrorback to summary
private ObjectProperty<Runnable> onError

Event 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.

sourceback to summary
private final String source

The source URI of the media;

tracksback to summary
private ObservableList<Track> tracks

An ObservableList of tracks contained in this media object. A Media object can contain multiple tracks, such as a video track with several audio track. This list is unmodifiable: the contents cannot be changed.

See Also
Track
tracksBackingback to summary
private final ObservableList<Track> tracksBacking
widthback to summary
private ReadOnlyIntegerWrapper width

The 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
height

Constructor Detail

Mediaback to summary
public Media(String source)

Constructs a Media instance. This is the only way to specify the media source. The source must represent a valid URI and is immutable. Only HTTP, HTTPS, FILE, and JAR URLs are supported. If the provided URL is invalid then an exception will be thrown. If an asynchronous error occurs, the error property 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 MediaException to 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 the error property.

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:String

The URI of the source media.

Exceptions
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.
  • if the URI string has a null scheme.
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 Detail

_setErrorback to summary
pack-priv void _setError(MediaException.Type type, String message)
_updateMediaback to summary
pack-priv void _updateMedia(Media _media)
durationPropertyback to summary
public ReadOnlyObjectProperty<Duration> durationProperty()
durationPropertyImplback to summary
private ReadOnlyObjectWrapper<Duration> durationPropertyImpl()
errorPropertyback to summary
public ReadOnlyObjectProperty<MediaException> errorProperty()
errorPropertyImplback to summary
private ReadOnlyObjectWrapper<MediaException> errorPropertyImpl()
getDurationback to summary
public final Duration getDuration()

Retrieve the duration in seconds of the media.

Returns:Duration

the duration of the media, Duration#UNKNOWN if unknown or Duration#INDEFINITE for live streams

getErrorback to summary
public final MediaException getError()

Return any error encountered in the media.

Returns:MediaException

a MediaException or null if there is no error.

getHeightback to summary
public final int getHeight()

Retrieve the height in pixels of the media.

Returns:int

the media height or zero if the height is undefined or unknown.

getMarkersback to summary
public final ObservableMap<String, Duration> getMarkers()

Retrieve the markers defined on this Media instance. If there are no markers the returned ObservableMap will be empty. Programmatic markers may be added by inserting entries in the returned Map.

Returns:ObservableMap<String, Duration>

the markers defined on this media source.

getMetadataback to summary
public final ObservableMap<String, Object> getMetadata()

Retrieve the metadata contained in this media source. If there are no metadata, the returned ObservableMap will be empty.

Returns:ObservableMap<String, Object>

the metadata contained in this media source.

getOnErrorback to summary
public final Runnable getOnError()

Retrieve the error handler to be called if an error occurs.

Returns:Runnable

the error handler or null if none is defined.

getSourceback to summary
public String getSource()

Retrieve the source URI of the media.

Returns:String

the media source URI as a String.

getTracksback to summary
public final ObservableList<Track> getTracks()

Retrieve the tracks contained in this media source. If there are no tracks, the returned ObservableList will be empty.

Returns:ObservableList<Track>

the tracks contained in this media source.

getTrackWithIDback to summary
private Track getTrackWithID(long trackID)
getWidthback to summary
public final int getWidth()

Retrieve the width in pixels of the media.

Returns:int

the media width or zero if the width is undefined or unknown.

heightPropertyback to summary
public ReadOnlyIntegerProperty heightProperty()
heightPropertyImplback to summary
private ReadOnlyIntegerWrapper heightPropertyImpl()
onErrorPropertyback to summary
public ObjectProperty<Runnable> onErrorProperty()
retrieveJfxLocatorback to summary
pack-priv Locator retrieveJfxLocator()
runMetadataParserback to summary
private void runMetadataParser()
setDurationback to summary
pack-priv final void setDuration(Duration value)
setErrorback to summary
private void setError(MediaException value)
setHeightback to summary
pack-priv final void setHeight(int value)
setOnErrorback to summary
public final void setOnError(Runnable value)

Set the event handler to be called when an error occurs.

Parameters
value:Runnable

the error event handler.

setWidthback to summary
pack-priv final void setWidth(int value)
updateMetadataback to summary
private synchronized void updateMetadata(Map<String, Object> metadata)
widthPropertyback to summary
public ReadOnlyIntegerProperty widthProperty()
widthPropertyImplback to summary
private ReadOnlyIntegerWrapper widthPropertyImpl()
javafx.scene.media back to summary

private Class Media._MetadataListener

extends Object
implements MetadataListener
Class Inheritance
All Implemented Interfaces
com.sun.media.jfxmedia.events.MetadataListener

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public void
onMetadata(final Map<String, Object> metadata)

Implements com.sun.media.jfxmedia.events.MetadataListener.onMetadata.

The metadata notification indicates a metadata has been reached or metadata value was changed during playback.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

_MetadataListenerback to summary
private _MetadataListener()

Method Detail

onMetadataback to summary
public void onMetadata(final Map<String, Object> metadata)

Implements com.sun.media.jfxmedia.events.MetadataListener.onMetadata.

Doc from com.sun.media.jfxmedia.events.MetadataListener.onMetadata.

The metadata notification indicates a metadata has been reached or metadata value was changed during playback.

Annotations
@Override
javafx.scene.media back to summary

private Class Media.InitLocator

extends Object
implements Runnable
Class Inheritance
All Implemented Interfaces
java.lang.Runnable

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public void
run()

Implements java.lang.Runnable.run.

Runs this operation.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

InitLocatorback to summary
private InitLocator()

Method Detail

runback to summary
public void run()

Implements java.lang.Runnable.run.

Doc from java.lang.Runnable.run.

Runs this operation.

Annotations
@Override