回 帖 发 新 帖 刷新版面

主题:关于视频的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);  
     
        } 


回复列表 (共2个回复)

沙发

可能是ECLIPSE的APPLETVIEWER和你在CMD下用的APPLETVIEW权限不一样.
APPLETVIEWER在运行的时候可以设置权限的.我记得ECLIPSE的默认设置是"拥有最大权限"
可能你CMD下运行的那个的默认值是不能访问其他资源吧.输个/?应该就很明白了.
在HTML中的APPLETVIEWER的权限极度有限,应该是不可能访问摄像头的.

所以请学习APPLET在浏览器下的权限.我知道的是不能访问文件,不能访问HTML文件所在的网址之外的任何网址.应该是不可能访问其他任何设备.最后一点我不保证,只是猜测.

如果你实在想用,也是可以的.采用JNI,使用网页插件的方式,使用C的程序才有权限访问摄像头.

板凳

上个问题解决了,我重启电脑后就可以用了
只是那个是在Java Project中,html双击后也可以显示摄像头所拍摄的画面

但是今天我把它移到Web Project中,用tomcat打开就不能加载
我不知道是否是我的路径什么有问题,麻烦知道的人帮我看看

Videotest1.java在E:\elearning\src\elearning目录下(elearning是包)

Videotest1.class在E:\elearning\WebRoot\WEB-INF\classes\elearning目录下
这是编译Videotest1.java后自动到这个目录下的

Videotest1.jsp在E:\elearning\WebRoot目录下

这样,Videotest1.jsp中的applet该怎么写?
我写的是
    <applet  codebase="WEB-INF/classes/"
            code="elearning.Videotest1.class" 
            name="Videotest1" 
            width="320" 
            height="270">    
    </applet>
可用http://127.0.0.1:7000/elearning/Videotest1.jsp(我的tomcat端口为7000)
浏览器打开后总是不行,说无法加载
我尝试改codebase,可都还是错的
但是在myEclipse中,用Run as java applet就可以加载

麻烦了……

我来回复

您尚未登录,请登录后再回复。点此登录或注册