Java Reference
In-Depth Information
These states are
•
Unrealized
: An unrealized
Player
instance does not have the information it needs
about the resources it must acquire in order to function. Many
Player
methods,
including
getContentType
,
setTimeBase
,
getTimeBase
,
setMediaTime
,
getControls
, and
getControl
, will fail if invoked on a
Player
in this state, and the
Player
will throw an
IllegalStateException
.
•
Realized
: An unrealized player moves to the realized state when you invoke its
realize
method. This transition can be a lengthy process as the
Player
instance
obtains system resources and works with the media content to determine its
content type or perform other operations. You can stop the realization process by
invoking the instance's
deallocate
method, but you must do so
before
the
Player
instance finishes transitioning to the realized state; once realized, a
Player
instance
cannot return to the unrealized state.
•
Prefetched
: A realized player may still need to do additional time-consuming
processing such as fill media buffers from the network or obtain exclusive
resources such as a hardware codec. To do this, you invoke the
Player
instance's
prefetch
method.
•
Started
: Once a
Player
instance has been realized and its contents and resources
have been prefetched, you can start playback by invoking the
Player
instance's
start
method.
1
This causes the
Player
instance to transition to the started state.
While in the started state, the instance runs and renders multimedia data until you
stop it by invoking
stop
or until it runs out of data to render. Invoking
stop
on a
started
Player
instance returns it to the prefetched state.
•
Closed
: From any other state, you can force a
Player
instance to release its
resources and move to the closed state by invoking its
close
method. Once
placed in this state, you must not attempt to use the instance again; it's ready for
reclamation by the garbage collector, and all you should do is set any references
to it to
null
.
As they say, the devil's in the details, so let's look at some actual code that renders
multimedia and controls its playback.
Oddly, you can usually bring a realized
Player
instance directly to the started state by invoking its
start
method. A lot of the tutorial examples you see on the Internet—including examples from Sun—
do this, but it's counter to the documentation that the MMAPI JSR provides, so I don't recommend it.
1.