在浏览器中运行Java程序?
问题描述:
伙计们,我想运行一个Java程序,该程序使用JMF在浏览器中显示网络摄像头视频.我在这里粘贴Java代码..不是小程序代码..
有什么可以帮助我的吗?
Guys, i wan to run a java program that using JMF to show webcam video in a browser..i tried applet but the result is negative..the applet running but view nothing..can someone help me on this..i paste here the java code..not the applet code..
any can help me??
import java.awt.BorderLayout;
import java.util.Vector;
import javax.media.*;
import javax.media.control.FormatControl;
import javax.swing.JFrame;
public class WebcamClass {
CaptureDeviceInfo cam;
MediaLocator locator;
Player player;
FormatControl formatControl;
public static void main ( String args [] ){
WebcamClass camera = new WebcamClass();
}
public WebcamClass(){
try{
// List out available Devices to Capture Video.
CaptureDeviceManager manager = new CaptureDeviceManager();
//System.out.println("List device : " + manager.toString());
Vector<capturedeviceinfo> list = manager.getDeviceList (null);
System.out.println("List device : " + list.toString());
for(CaptureDeviceInfo temp : list){
// Checking whether the current device supports VfW
// VfW = Video for Windows
if(temp.getName().startsWith("vfw:"))
{
System.out.println("Found : "+temp.getName().substring(4));
// Selecting the very first device that supports VfW
cam = temp;
System.out.println("Selected : "+cam.getName().substring(4));
break;
}
}
System.out.println("Put it on work!...");
// Getting the MediaLocator for Selected device.
// MediaLocator describes the location of media content
//locator = cam.getLocator();
String source = "vfw://0";
//source = "";
locator = new MediaLocator(source);
if(locator != null){
System.out.println("locate :" + locator.toString());
// Create a Player for Media Located by MediaLocator
player = Manager.createRealizedPlayer(locator);
if(player != null){
// Starting the player
player.start();
// Creating a Frame to display Video
JFrame f = new JFrame();
f.setTitle("Display Webcam");
f.setLayout(new BorderLayout());
// Adding the Visual Component to display Video captured by Player
// from URL provided by MediaLocator
f.add(player.getVisualComponent(), BorderLayout.CENTER);
f.pack();
f.setVisible(true);
}
}
}catch(Exception e){
System.out.println(e);
}
}
}
答
我不知道您要在那里尝试-但这不是applet.
请遵循:
Applet教程 [
I don''t know what you ae trying there - but that''s no applet.
Follow this:
Applet Tutorial[^]
To get a valid applet. Also needs the browser to accept the Java Applet.
If that support is disabled by default, you might never notice the applet is there.