主题:关于视频的applet问题,急……
我在myEclipse中使用Run As Java Applet可以加载小程序,并在小程序应用窗口中可以显示出摄像头拍摄到的画面
但在CMD中使用appletviewer就出错,提示信息如下:
java.io.IOException:Could not connect to capture device
javax.media.NoPlayerException:Error instantiating class:com.sun.media.protocol.vfw.DataSource
FATAL ERROR:Could not create player for vfw://0
java.lang.Error:Could not create player for vfw://0
at Videotest1.Fatal(Videotest1.java:126)
at Videotest1.init(Videotest1.java:49)
at sun.applet.AppletPanel.run(AppletPanel.java:379)
at java.lang.Thread.run(Thread.java:595)
我如果直接双击.html文件,就会提示notinited
请问这个问题该怎么解决啊?加急……
我的Videotest1.java代码如下:
import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
import java.lang.String;
import java.net.URL;
import java.io.IOException;
import java.util.Properties;
import javax.media.*;
public class Videotest1 extends Applet implements ControllerListener {
// media Player
Player player = null;
CaptureDeviceInfo infor ;
MediaLocator mrl=null;
// component in which video is playing
Component visualComponent = null;
// controls gain, position, start, stop
Component controlComponent = null;
// displays progress during download
long CachingSize = 0L;
Panel panel = null;
int controlPanelHeight = 0;
int videoWidth = 0;
int videoHeight = 0;
public Videotest1() {
super();
}
public void destroy() {
// Put your code here
player.close();
}
public void init() {
// Put your code here
setLayout(null);
panel = new Panel();
panel.setLayout( null );
add(panel);
panel.setBounds(0, 0, 320, 240);
String url ="vfw:Microsoft WDM Image Capture (Win32):0";
infor = CaptureDeviceManager.getDevice(url);
mrl = infor.getLocator();
try {
player = Manager.createPlayer(mrl);
}
catch (NoPlayerException e) {
System.out.println(e);
Fatal("Could not create player for " + mrl);
}
catch (IOException e) {
Fatal("IO exception creating player for " + mrl);
}
catch (Exception e) {
Fatal("exception!");
}
// Add ourselves as a listener for a player 's events
player.addControllerListener(this);
}
public void start() {
if (player != null)
player.start();
}
public void stop() {
// Put your code here
if (player != null) {
player.stop();
player.deallocate();
}
}
public synchronized void controllerUpdate(ControllerEvent event) {
// If we 're getting messages from a dead player,
// just leave
if (player == null)
return;
// When the player is Realized, get the visual
// and control components and add them to the Applet
if (event instanceof RealizeCompleteEvent) {
int width = 320;
int height = 0;
if (controlComponent == null)
if (( controlComponent =
player.getControlPanelComponent()) != null) {
controlPanelHeight = controlComponent.getPreferredSize().height;
panel.add(controlComponent);
height += controlPanelHeight;
}
if (visualComponent == null)
if (( visualComponent =
player.getVisualComponent())!= null) {
panel.add(visualComponent);
Dimension videoSize = visualComponent.getPreferredSize();
videoWidth = videoSize.width;
videoHeight = videoSize.height;
width = videoWidth;
height += videoHeight;
visualComponent.setBounds(0, 0, videoWidth, videoHeight);
}
panel.setBounds(0, 0, width, height);
if (controlComponent != null) {
controlComponent.setBounds(0, videoHeight,
width, controlPanelHeight);
controlComponent.invalidate();
}
setVisible(true);
player.prefetch();
} else if(event instanceof PrefetchCompleteEvent) {
player.start();
System.out.println("prefetched");
}
}
void Fatal (String s) {
System.err.println("FATAL ERROR: " + s);
throw new Error(s);
}
}
但在CMD中使用appletviewer就出错,提示信息如下:
java.io.IOException:Could not connect to capture device
javax.media.NoPlayerException:Error instantiating class:com.sun.media.protocol.vfw.DataSource
FATAL ERROR:Could not create player for vfw://0
java.lang.Error:Could not create player for vfw://0
at Videotest1.Fatal(Videotest1.java:126)
at Videotest1.init(Videotest1.java:49)
at sun.applet.AppletPanel.run(AppletPanel.java:379)
at java.lang.Thread.run(Thread.java:595)
我如果直接双击.html文件,就会提示notinited
请问这个问题该怎么解决啊?加急……
我的Videotest1.java代码如下:
import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
import java.lang.String;
import java.net.URL;
import java.io.IOException;
import java.util.Properties;
import javax.media.*;
public class Videotest1 extends Applet implements ControllerListener {
// media Player
Player player = null;
CaptureDeviceInfo infor ;
MediaLocator mrl=null;
// component in which video is playing
Component visualComponent = null;
// controls gain, position, start, stop
Component controlComponent = null;
// displays progress during download
long CachingSize = 0L;
Panel panel = null;
int controlPanelHeight = 0;
int videoWidth = 0;
int videoHeight = 0;
public Videotest1() {
super();
}
public void destroy() {
// Put your code here
player.close();
}
public void init() {
// Put your code here
setLayout(null);
panel = new Panel();
panel.setLayout( null );
add(panel);
panel.setBounds(0, 0, 320, 240);
String url ="vfw:Microsoft WDM Image Capture (Win32):0";
infor = CaptureDeviceManager.getDevice(url);
mrl = infor.getLocator();
try {
player = Manager.createPlayer(mrl);
}
catch (NoPlayerException e) {
System.out.println(e);
Fatal("Could not create player for " + mrl);
}
catch (IOException e) {
Fatal("IO exception creating player for " + mrl);
}
catch (Exception e) {
Fatal("exception!");
}
// Add ourselves as a listener for a player 's events
player.addControllerListener(this);
}
public void start() {
if (player != null)
player.start();
}
public void stop() {
// Put your code here
if (player != null) {
player.stop();
player.deallocate();
}
}
public synchronized void controllerUpdate(ControllerEvent event) {
// If we 're getting messages from a dead player,
// just leave
if (player == null)
return;
// When the player is Realized, get the visual
// and control components and add them to the Applet
if (event instanceof RealizeCompleteEvent) {
int width = 320;
int height = 0;
if (controlComponent == null)
if (( controlComponent =
player.getControlPanelComponent()) != null) {
controlPanelHeight = controlComponent.getPreferredSize().height;
panel.add(controlComponent);
height += controlPanelHeight;
}
if (visualComponent == null)
if (( visualComponent =
player.getVisualComponent())!= null) {
panel.add(visualComponent);
Dimension videoSize = visualComponent.getPreferredSize();
videoWidth = videoSize.width;
videoHeight = videoSize.height;
width = videoWidth;
height += videoHeight;
visualComponent.setBounds(0, 0, videoWidth, videoHeight);
}
panel.setBounds(0, 0, width, height);
if (controlComponent != null) {
controlComponent.setBounds(0, videoHeight,
width, controlPanelHeight);
controlComponent.invalidate();
}
setVisible(true);
player.prefetch();
} else if(event instanceof PrefetchCompleteEvent) {
player.start();
System.out.println("prefetched");
}
}
void Fatal (String s) {
System.err.println("FATAL ERROR: " + s);
throw new Error(s);
}
}