📄 jmfapp-statehelper.html
字号:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<meta name="GENERATOR" content="Quadralay WebWorks Publisher 5.0.2">
<meta name="TEMPLATEBASE" content="Portable HTML">
<meta name="LASTUPDATED" content="11/23/99 11:48:13">
<title>StateHelper </title>
</head>
<body link="#3366CC" vlink="#9999CC" text="#000000" alink="#0000CC" bgcolor="#FFFFFF"
background="images/backgrnd.gif">
<table width="100%" border="0" align="left" cellpadding="0" cellspacing="0">
<tr>
<td><a href="JMFTOC.html">CONTENTS</a> |
<a href="JMFApp-Applet.html">PREV </a> |
<a href="JMFApp-Demux.html">NEXT</a> |
<a href="JMFIX.html">INDEX</a></td>
<td align="right"><em>JMF 2.0 API Guide</em>
</tr>
</table>
<p><br clear="all">
</p>
<hr align="left">
<blockquote>
<div align="right">
<a name="85025"> </a><font size="3" face="Palatino, Times New Roman, Times, serif">B <br></font>
</div>
<div align="right">
<h2>
<a name="85027"> </a><font color="#003366" face="Palatino, Times New Roman, Times, serif">StateHelper</font>
</h2>
</div>
<p>
<a name="85028"> </a><font face="Palatino, Times New Roman, Times, serif"><code>StateHelper</code> is a helper class that implements the <code>ControllerListener</code> interface and can be used to manage the state of a <code>Processor</code>. This helper class is used in examples 5-4, 5-5, and 5-6 in<a href="JMFCapturing.html#98540">Capturing Time-Based Media with JMF</a>. <a href="JMFCapturing.html#98540"></a>
<table border="1" bordercolorlight="#FFFFFF" bordercolordark="#000000"
cellpadding="5" cellspacing="0">
<caption><b><i><font face="Palatino, Times New Roman, Times, serif"><a name="84658"> </a>Example B-1: StateHelper (1 of 3)</font></i></b></caption>
<tr>
<td><font face="Palatino, Times New Roman, Times, serif"><pre>
<a name="85057"> </a><code>import javax.media.*;
</code><a name="85058"> </a>
<a name="85059"> </a>
<a name="85060"> </a><code>public class StateHelper implements javax.media.ControllerListener {
</code><a name="85061"> </a>
<a name="85062"> </a><code> Player player = null;
</code><a name="85063"> </a><code> boolean configured = false;
</code><a name="85064"> </a><code> boolean realized = false;
</code><a name="85065"> </a><code> boolean prefetched = false;
</code><a name="85066"> </a><code> boolean eom = false;
</code><a name="85067"> </a><code> boolean failed = false;
</code><a name="85068"> </a><code> boolean closed = false;
</code><a name="85069"> </a><code>
</code><a name="85070"> </a><code> public StateHelper(Player p) {
</code><a name="85071"> </a><code> player = p;
</code><a name="85072"> </a><code> p.addControllerListener(this);
</code><a name="84706"> </a><code> }
</code><a name="85082"> </a>
<a name="85083"> </a> public boolean configure(int timeOutMillis) {
<a name="85084"> </a> long startTime = System.currentTimeMillis();
<a name="85085"> </a> synchronized (this) {
<a name="85086"> </a> if (player instanceof Processor)
<a name="85087"> </a> ((Processor)player).configure();
<a name="85088"> </a> else
<a name="85080"> </a> return false;
</pre>
</font></td>
</tr>
<tr>
<td><font face="Palatino, Times New Roman, Times, serif"><pre>
<a name="85315"> </a> while (!configured && !failed) {
<a name="85316"> </a> try {
<a name="85317"> </a> wait(timeOutMillis);
<a name="85318"> </a> } catch (InterruptedException ie) {
<a name="85319"> </a> }
<a name="85320"> </a> if (System.currentTimeMillis() - startTime > timeOutMillis)
<a name="85321"> </a> break;
<a name="85322"> </a> }
<a name="85323"> </a> }
<a name="85324"> </a> return configured;
<a name="85325"> </a> }
<a name="85326"> </a>
<a name="85327"> </a> public boolean realize(int timeOutMillis) {
<a name="85328"> </a> long startTime = System.currentTimeMillis();
<a name="85329"> </a> synchronized (this) {
<a name="85330"> </a> player.realize();
<a name="85331"> </a> while (!realized && !failed) {
<a name="85332"> </a> try {
<a name="85333"> </a> wait(timeOutMillis);
<a name="85334"> </a> } catch (InterruptedException ie) {
<a name="85335"> </a> }
<a name="85336"> </a> if (System.currentTimeMillis() - startTime > timeOutMillis)
<a name="85337"> </a> break;
<a name="85338"> </a> }
<a name="85339"> </a> }
<a name="85340"> </a> return realized;
<a name="85341"> </a> }
<a name="85342"> </a>
<a name="85343"> </a> public boolean prefetch(int timeOutMillis) {
<a name="85344"> </a> long startTime = System.currentTimeMillis();
<a name="85345"> </a> synchronized (this) {
<a name="85346"> </a> player.prefetch();
<a name="85347"> </a> while (!prefetched && !failed) {
<a name="85348"> </a> try {
<a name="85349"> </a> wait(timeOutMillis);
<a name="85350"> </a> } catch (InterruptedException ie) {
<a name="85351"> </a> }
<a name="85352"> </a> if (System.currentTimeMillis() - startTime > timeOutMillis)
<a name="85353"> </a> break;
<a name="85354"> </a> }
<a name="85355"> </a> }
<a name="85356"> </a> return prefetched && !failed;
<a name="84806"> </a> }
<a name="85362"> </a> public boolean playToEndOfMedia(int timeOutMillis) {
<a name="85363"> </a> long startTime = System.currentTimeMillis();
<a name="85364"> </a> eom = false;
<a name="85365"> </a> synchronized (this) {
<a name="85360"> </a> player.start();
</pre>
</font></td>
</tr>
<tr>
<td><font face="Palatino, Times New Roman, Times, serif"><pre>
<a name="85372"> </a> while (!eom && !failed) {
<a name="85373"> </a> try {
<a name="85374"> </a> wait(timeOutMillis);
<a name="85375"> </a> } catch (InterruptedException ie) {
<a name="85376"> </a> }
<a name="85377"> </a> if (System.currentTimeMillis() - startTime > timeOutMillis)
<a name="85378"> </a> break;
<a name="85379"> </a> }
<a name="85380"> </a> }
<a name="85381"> </a> return eom && !failed;
<a name="85382"> </a> }
<a name="85383"> </a>
<a name="85384"> </a> public void close() {
<a name="85385"> </a> synchronized (this) {
<a name="85386"> </a> player.close();
<a name="85387"> </a> while (!closed) {
<a name="85388"> </a> try {
<a name="85389"> </a> wait(100);
<a name="85390"> </a> } catch (InterruptedException ie) {
<a name="85391"> </a> }
<a name="85392"> </a> }
<a name="85393"> </a> }
<a name="85394"> </a> player.removeControllerListener(this);
<a name="85395"> </a> }
<a name="85396"> </a>
<a name="85397"> </a> public synchronized void controllerUpdate(ControllerEvent ce) {
<a name="85398"> </a> if (ce instanceof RealizeCompleteEvent) {
<a name="85399"> </a> realized = true;
<a name="85400"> </a> } else if (ce instanceof ConfigureCompleteEvent) {
<a name="85401"> </a> configured = true;
<a name="85402"> </a> } else if (ce instanceof PrefetchCompleteEvent) {
<a name="85403"> </a> prefetched = true;
<a name="85404"> </a> } else if (ce instanceof EndOfMediaEvent) {
<a name="85405"> </a> eom = true;
<a name="85406"> </a> } else if (ce instanceof ControllerErrorEvent) {
<a name="85407"> </a> failed = true;
<a name="85408"> </a> } else if (ce instanceof ControllerClosedEvent) {
<a name="85409"> </a> closed = true;
<a name="85410"> </a> } else {
<a name="85411"> </a> return;
<a name="85412"> </a> }
<a name="85413"> </a> notifyAll();
<a name="85414"> </a> }
<a name="85415"> </a>}
</pre>
</font></td>
</tr>
</table>
</font>
</p>
</blockquote>
<br clear="all">
<hr>
<a href="JMFTOC.html">CONTENTS</a> |
<a href="JMFApp-Applet.html">PREV </a> |
<a href="JMFApp-Demux.html">NEXT</a> |
<a href="JMFIX.html">INDEX</a></td>
<br>
<hr>
<em>
<a href="copyright.html">Copyright</a> ©
1998-1999 Sun Microsystems, Inc. All Rights Reserved.
</em>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -