public final class Media
extends java.lang.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
Track
s 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.
MediaPlayer
,
MediaException
Type | Property and Description |
---|---|
<any> |
duration
The duration in seconds of the source media.
|
<any> |
error
A property set to a MediaException value when an error occurs.
|
ReadOnlyIntegerProperty |
height
The height in pixels of the source media.
|
<any> |
onError
Event handler called when an error occurs.
|
ReadOnlyIntegerProperty |
width
The width in pixels of the source media.
|
Modifier and Type | Class and Description |
---|---|
private class |
Media._MetadataListener |
private class |
Media.InitLocator |
Modifier and Type | Field and Description |
---|---|
private <any> |
duration
The duration in seconds of the source media.
|
private <any> |
error
A property set to a MediaException value when an error occurs.
|
private ReadOnlyIntegerWrapper |
height
The height in pixels of the source media.
|
private Locator |
jfxLocator
Locator used by the jfxmedia player, MediaPlayer needs access to this
|
private MetadataParser |
jfxParser |
private <any> |
markers
The markers defined on this media source.
|
private <any> |
metadata
An
ObservableMap of metadata which can contain information about
the media. |
private <any> |
metadataBacking |
private MetadataListener |
metadataListener |
private <any> |
onError
Event handler called when an error occurs.
|
private java.lang.String |
source
The source URI of the media;
|
private <any> |
tracks
An
ObservableList of tracks contained in this media object. |
private <any> |
tracksBacking |
private ReadOnlyIntegerWrapper |
width
The width in pixels of the source media.
|
Constructor and Description |
---|
Media(java.lang.String source)
Constructs a
Media instance. |
Modifier and Type | Method and Description |
---|---|
(package private) void |
_setError(MediaException.Type type,
java.lang.String message) |
(package private) void |
_updateMedia(com.sun.media.jfxmedia.Media _media) |
<any> |
durationProperty()
The duration in seconds of the source media.
|
private <any> |
durationPropertyImpl() |
<any> |
errorProperty()
A property set to a MediaException value when an error occurs.
|
private <any> |
errorPropertyImpl() |
Duration |
getDuration()
Retrieve the duration in seconds of the media.
|
MediaException |
getError()
Return any error encountered in the media.
|
int |
getHeight()
Retrieve the height in pixels of the media.
|
<any> |
getMarkers()
Retrieve the markers defined on this
Media instance. |
<any> |
getMetadata()
Retrieve the metadata contained in this media source.
|
java.lang.Runnable |
getOnError()
Retrieve the error handler to be called if an error occurs.
|
java.lang.String |
getSource()
Retrieve the source URI of the media.
|
<any> |
getTracks()
Retrieve the tracks contained in this media source.
|
private Track |
getTrackWithID(long trackID) |
int |
getWidth()
Retrieve the width in pixels of the media.
|
ReadOnlyIntegerProperty |
heightProperty()
The height in pixels of the source media.
|
private ReadOnlyIntegerWrapper |
heightPropertyImpl() |
<any> |
onErrorProperty()
Event handler called when an error occurs.
|
(package private) Locator |
retrieveJfxLocator() |
private void |
runMetadataParser() |
(package private) void |
setDuration(Duration value) |
private void |
setError(MediaException value) |
(package private) void |
setHeight(int value) |
void |
setOnError(java.lang.Runnable value)
Set the event handler to be called when an error occurs.
|
(package private) void |
setWidth(int value) |
private void |
updateMetadata(java.util.Map<java.lang.String,java.lang.Object> metadata) |
ReadOnlyIntegerProperty |
widthProperty()
The width in pixels of the source media.
|
private ReadOnlyIntegerWrapper |
widthPropertyImpl() |
public <any> errorProperty
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.getError()
public <any> onErrorProperty
getOnError()
,
setOnError(Runnable)
public ReadOnlyIntegerProperty widthProperty
getWidth()
public ReadOnlyIntegerProperty heightProperty
getHeight()
public <any> durationProperty
Duration#UNKNOWN
.getDuration()
private <any> error
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.MediaException
private <any> onError
private MetadataListener metadataListener
private <any> metadata
ObservableMap
of metadata which can contain information about
the media. Metadata entries use String
s for keys and contain
Object
values. This map is unmodifiable: its contents or stored
values cannot be changed.private final <any> metadataBacking
private ReadOnlyIntegerWrapper width
height
private ReadOnlyIntegerWrapper height
width
private <any> duration
Duration#UNKNOWN
.private <any> tracks
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.Track
private final <any> tracksBacking
private <any> markers
private final java.lang.String source
private final Locator jfxLocator
private MetadataParser jfxParser
public Media(java.lang.String source)
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 URL
s 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:
See java.net.URI for more information about URI formatting in general. JAR URL syntax is specified in java.net.JarURLConnection.
source
- The URI of the source media.java.lang.NullPointerException
- if the URI string is null
.java.lang.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.java.lang.IllegalArgumentException
- if the URI string has a null
scheme.java.lang.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
).private void setError(MediaException value)
public final MediaException getError()
MediaException
or null
if there is no error.public <any> errorProperty()
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.getError()
private <any> errorPropertyImpl()
public final void setOnError(java.lang.Runnable value)
value
- the error event handler.public final java.lang.Runnable getOnError()
null
if none is defined.public <any> onErrorProperty()
getOnError()
,
setOnError(Runnable)
public final <any> getMetadata()
ObservableMap
will be empty.final void setWidth(int value)
public final int getWidth()
public ReadOnlyIntegerProperty widthProperty()
getWidth()
private ReadOnlyIntegerWrapper widthPropertyImpl()
final void setHeight(int value)
public final int getHeight()
public ReadOnlyIntegerProperty heightProperty()
getHeight()
private ReadOnlyIntegerWrapper heightPropertyImpl()
final void setDuration(Duration value)
public final Duration getDuration()
Duration#UNKNOWN
if unknown or Duration#INDEFINITE
for live streamspublic <any> durationProperty()
Duration#UNKNOWN
.getDuration()
private <any> durationPropertyImpl()
public final <any> getTracks()
ObservableList
will be empty.public final <any> getMarkers()
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
.private void runMetadataParser()
public java.lang.String getSource()
String
.Locator retrieveJfxLocator()
private Track getTrackWithID(long trackID)
void _updateMedia(com.sun.media.jfxmedia.Media _media)
void _setError(MediaException.Type type, java.lang.String message)
private void updateMetadata(java.util.Map<java.lang.String,java.lang.Object> metadata)