Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: 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);
    }
}
}
Posted 4-Oct-12 0:35am
matpyam337
Edited 4-Oct-12 0:41am
TorstenH.33.8K
v3

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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.
  Permalink  
Comments
matpyam at 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. at 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)

  Print Answers RSS
0 OriginalGriff 381
1 Sergey Alexandrovich Kryukov 245
2 Marcin Kozub 225
3 Praneet Nadkar 217
4 /\jmot 189
0 OriginalGriff 8,284
1 Sergey Alexandrovich Kryukov 7,407
2 DamithSL 5,614
3 Maciej Los 4,989
4 Manas Bhardwaj 4,986


Advertise | Privacy | Mobile
Web02 | 2.8.1411023.1 | Last Updated 4 Oct 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100