public interface PlayerListener
PlayerListener
is the interface for receiving asynchronous events
generated by Players
. Applications may implement this interface a
nd register their implementations with the
addPlayerListener
method in Player
.
A number of standard Player
events are defined here in this
interface. Event types are defined as strings to support extensibility as
different implementations may introduce proprietary events by adding new event
types. To avoid name conflicts, proprietary events should be named with the
"reverse-domainname" convention. For example, a company named
"mycompany" should name its proprietary event names with strings
like "com.mycompany.myEvent" etc.
Applications that rely on proprietary events may not function properly across
different implementations. In order to make the applications that use those
events to behave well in environments that don't implement them,
String.equals()
should be used to check the event.
Code fragment for catching standard events in playerUpdate()
if (eventType == PlayerListener.STARTED) {...} |
Code fragment for catching proprietary events in playerUpdate()
if (eventType.equals("com.company.myEvent")) {...} |
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
CLOSED
Posted when a
Player is closed. |
static java.lang.String |
DEVICE_AVAILABLE
Posted when the system or another higher priority application has
released an exclusive device which is now available to the
Player . |
static java.lang.String |
DEVICE_UNAVAILABLE
Posted when the system or another higher priority application has
temporarily taken control of an exclusive device which was previously
available to the
Player . |
static java.lang.String |
DURATION_UPDATED
Posted when the duration of a
Playe r is updated. |
static java.lang.String |
END_OF_MEDIA
Posted when a
Player has reached the end of the media. |
static java.lang.String |
ERROR
Posted when an error had occurred.
|
static java.lang.String |
STARTED
Posted when a
Player is started. |
static java.lang.String |
STOPPED
Posted when a
Player stops in response to the
Player.stop() method call. |
static java.lang.String |
VOLUME_CHANGED
Posted when the volume of an audio device is changed.
|
Modifier and Type | Method and Description |
---|---|
void |
playerUpdate(Player player,
java.lang.String event,
java.lang.Object eventData)
This method is called to deliver an event to a registered listener when
a
Player event is observed. |
static final java.lang.String STARTED
Player
is started. When this event is received,
the eventData
parameter will be a Long
object
designating the media time when the Player
is started.
Value "started"
is assigned to STARTED
.
static final java.lang.String STOPPED
Player
stops in response to the
Player.stop()
method call. When this event is
received, the eventData
parameter will be a Long
object designating the media time when the Player
stopped.
Value "stopped"
is assigned to STOPPED
.
static final java.lang.String END_OF_MEDIA
Player
has reached the end of the media. When
this event is received, the eventData
parameter will be a
Long
object designating the media time when the
Player
reached end of media and stopped.
Value "endOfMedia"
is assigned to END_OF_MEDIA
.
static final java.lang.String DURATION_UPDATED
Playe
r is updated. This happens
for some media types where the duration cannot be derived ahead of time.
It can only be derived after the media is played for a period of time --
for example, when it reaches a key frame with duration info; or when it
reaches the end of media.
When this event is received, the eventData
parameter will be
a Long
object designating the duration of the media.
Value "durationUpdated"
is assigned to
DURATION_UPDATED
.
static final java.lang.String DEVICE_UNAVAILABLE
Player
.
The Player
will be in the REALIZED state when this
event is received.
This event must be followed by either a DEVICE_AVAILABLE
event
when the device becomes available again, or an ERROR
event if the
device becomes permanently unavailable.
The eventData
parameter is a String
specifying
the name of the device.
Value "deviceUnavailable"
is assigned to
DEVICE_UNAVAILABLE
.
static final java.lang.String DEVICE_AVAILABLE
Player
.
The Player
will be in the REALIZED state when this
event is received. The application may acquire the device with the
prefetch
or start
method.
A DEVICE_UNAVAILABLE
event must precede this event.
The eventData
parameter is a String
specifying
the name of the device.
Value "deviceAvailable"
is assigned to
DEVICE_AVAILABLE
.
static final java.lang.String VOLUME_CHANGED
eventData
parameter will be a
VolumeControl
object. The new volume can be queried from the
VolumeControl
.
Value "volumeChanged"
is assigned to
VOLUME_CHANGED
.
static final java.lang.String ERROR
eventData
parameter will be a String
object
specifying the error message.
Value "error"
is assigned to ERROR
.
static final java.lang.String CLOSED
Player
is closed. When this event is received,
the eventData
parameter is null
.
Value "close"
d is assigned to CLOSED
.
void playerUpdate(Player player, java.lang.String event, java.lang.Object eventData)
Player
event is observed.player
- the player which generated the eventevent
- the event generated as defined by the enumerated typeseventData
- the associated event dataCopyright (c) 2014, Oracle and/or its affiliates. All rights reserved. Use of this specification is subject to license terms.