Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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??

Java
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);
    }
}
}
Posted
Updated 3-Oct-12 23:41pm
v3

1 solution

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.
 
Share this answer
 
Comments
matpyam 5-Oct-12 7:49am    
ok..tq..
but i give above is the example of java program..
i already create the applet file..but when i run the applet using BlueJ, there are no output..through bluej aso i run the coding above, there are output..when i change it into applet..just applet window prompt that pop out and there is nothing in it..blank..
but, when i try the simple applet..applet "Hello World", it succeed..i also don no what is wrong with my coding or my desktop..:(
TorstenH. 5-Oct-12 8:23am    
When the other applet is running, but your applet does not do so - then it's your applet that is not valid. Do you have any logging? Is there some interaction or is nothing happening? Try log4j, that's a common logging solution.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900