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
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 |
---|---|
ReadOnlyObjectProperty<Duration> |
duration
The duration in seconds of the source media.
|
ReadOnlyObjectProperty<MediaException> |
error
A property set to a MediaException value when an error occurs.
|
ReadOnlyIntegerProperty |
height
The height in pixels of the source media.
|
ObjectProperty<Runnable> |
onError
Event handler called when an error occurs.
|
ReadOnlyIntegerProperty |
width
The width in pixels of the source media.
|
Constructor and Description |
---|
Media(String source)
Constructs a
Media instance. |
Modifier and Type | Method and 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.
|
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.
|
ObservableMap<String,Duration> |
getMarkers()
Retrieve the markers defined on this
Media instance. |
ObservableMap<String,Object> |
getMetadata()
Retrieve the metadata contained in this media source.
|
Runnable |
getOnError()
Retrieve the error handler to be called if an error occurs.
|
String |
getSource()
Retrieve the source URI of the media.
|
ObservableList<Track> |
getTracks()
Retrieve the tracks contained in this media source.
|
int |
getWidth()
Retrieve the width in pixels of the media.
|
ReadOnlyIntegerProperty |
heightProperty()
The height in pixels of the source media.
|
ObjectProperty<Runnable> |
onErrorProperty()
Event handler called when an error occurs.
|
void |
setOnError(Runnable value)
Set the event handler to be called when an error occurs.
|
ReadOnlyIntegerProperty |
widthProperty()
The width in pixels of the source media.
|
public ReadOnlyObjectProperty<MediaException> 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 ObjectProperty<Runnable> onErrorProperty
getOnError()
,
setOnError(Runnable)
public ReadOnlyIntegerProperty widthProperty
getWidth()
public ReadOnlyIntegerProperty heightProperty
getHeight()
public ReadOnlyObjectProperty<Duration> durationProperty
Duration.UNKNOWN
.getDuration()
public Media(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, 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.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 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
).public final MediaException getError()
MediaException
or null
if there is no error.public ReadOnlyObjectProperty<MediaException> 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 final void setOnError(Runnable value)
value
- the error event handler.public final Runnable getOnError()
null
if none is defined.public ObjectProperty<Runnable> onErrorProperty()
getOnError()
,
setOnError(Runnable)
public final ObservableMap<String,Object> getMetadata()
ObservableMap
will be empty.public final int getWidth()
public ReadOnlyIntegerProperty widthProperty()
getWidth()
public final int getHeight()
public ReadOnlyIntegerProperty heightProperty()
getHeight()
public final Duration getDuration()
Duration.UNKNOWN
if unknown or Duration.INDEFINITE
for live streamspublic ReadOnlyObjectProperty<Duration> durationProperty()
Duration.UNKNOWN
.getDuration()
public final ObservableList<Track> getTracks()
ObservableList
will be empty.public final ObservableMap<String,Duration> 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
.Copyright (c) 2008, 2015, Oracle and/or its affiliates. All rights reserved.