📄 processorvideopanel.java
字号:
/*
* @(#)ProcessorVideoPanel.java 1.2 01/03/13
*
* Copyright (c) 1999-2001 Sun Microsystems, Inc. All Rights Reserved.
*
* Sun grants you ("Licensee") a non-exclusive, royalty free, license to use,
* modify and redistribute this software in source and binary code form,
* provided that i) this copyright notice and license appear on all copies of
* the software; and ii) Licensee does not utilize the software in a manner
* which is disparaging to Sun.
*
* This software is provided "AS IS," without a warranty of any kind. ALL
* EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY
* IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
* NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE
* LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING
* OR DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR ITS
* LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT,
* INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER
* CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF
* OR INABILITY TO USE SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGES.
*
* This software is not designed or intended for use in on-line control of
* aircraft, air traffic, aircraft navigation or aircraft communications; or in
* the design, construction, operation or maintenance of any nuclear
* facility. Licensee represents and warrants that it will not use or
* redistribute the Software for such purposes.
*
* Modified by Frank McCown for use in the ROWC distributed media system on
* May 2002.
*/
import java.awt.*;
import javax.media.*;
import javax.media.control.TrackControl;
import javax.media.format.*;
import javax.media.protocol.*;
import javax.media.protocol.DataSource;
public class ProcessorVideoPanel extends javax.swing.JPanel implements ControllerListener
{
private Player p;
private Object waitSync = new Object();
private boolean stateTransitionOK = true;
private Component control;
private Component visual;
/**
* Given a DataSource, create a player and use it to playback the media.
* Return true if successful playing the DataSource, false otherwise.
*/
public boolean open(DataSource ds)
{
System.err.println("create player for: " + ds.getContentType());
try
{
p = Manager.createPlayer(ds);
}
catch (Exception e)
{
System.err.println("Failed to create a player from the given DataSource: " + e);
return false;
}
p.addControllerListener(this);
// Realize the player.
p.prefetch();
if (!waitForState(p.Prefetched))
{
System.err.println("Failed to realize the player.");
return false;
}
// Display the visual & control component if there's one.
setLayout(new BorderLayout());
if ((visual = p.getVisualComponent()) != null)
add("Center", visual);
if ((control = p.getControlPanelComponent()) != null)
add("South", control);
// Start the player.
p.start();
setVisible(true);
setSize(getPreferredSize());
return true;
}
public void addNotify()
{
super.addNotify();
// pack();
}
/**
* Block until the player has transitioned to the given state.
* Return false if the transition failed.
*/
boolean waitForState(int state)
{
synchronized (waitSync) {
try
{
while (p.getState() < state && stateTransitionOK)
waitSync.wait();
}
catch (Exception e) {}
}
return stateTransitionOK;
}
/**
* Controller Listener.
*/
public void controllerUpdate(ControllerEvent evt)
{
if (evt instanceof ConfigureCompleteEvent ||
evt instanceof RealizeCompleteEvent ||
evt instanceof PrefetchCompleteEvent)
{
synchronized (waitSync)
{
stateTransitionOK = true;
waitSync.notifyAll();
}
}
else if (evt instanceof ResourceUnavailableEvent)
{
synchronized (waitSync)
{
stateTransitionOK = false;
waitSync.notifyAll();
}
}
else if (evt instanceof EndOfMediaEvent)
{
// System.out.println("\nEndOfMediaEvent\n");
// p.close();
// Only a video file would produce an EndOfMediaEvent, so re-start
p.setMediaTime(new Time(0));
p.start();
}
else if (evt instanceof SizeChangeEvent)
{
}
}
public void stop()
{
p.stop();
p.close();
}
public Dimension getPreferredSize()
{
int w = 0, h = 0;
if (visual != null)
{
Dimension size = visual.getPreferredSize();
w = size.width;
h = size.height;
}
if (control != null)
{
Dimension size = control.getPreferredSize();
if (w == 0)
w = size.width;
h += size.height;
}
if (w < 160)
w = 160;
return new Dimension(w, h);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -