Solved

Java video class

Posted on 2013-06-30
5
390 Views
Last Modified: 2013-07-04
Anyone direct me to a BASIC java class that will capture, display and record video from a USB webcam.  I have looked through a lot of code and it is either way to elaborate or incomplete.  I need to include a class in a program I have that can be called to start/stop recording by a click of a button.
0
Comment
Question by:sargent240
  • 3
  • 2
5 Comments
 
LVL 16

Accepted Solution

by:
krakatoa earned 500 total points
ID: 39289281
Here's something I was playing around with, which works but needs attention. Maybe you can take it further.

import java.awt.BorderLayout;
import java.util.Vector;

import javax.media.CaptureDeviceInfo;
import javax.media.CaptureDeviceManager;
import javax.media.Manager;
import javax.media.MediaLocator;
import javax.media.Player;
import javax.media.control.FormatControl;
import javax.swing.JFrame;

public class MyCam{

	CaptureDeviceInfo cam;	
	MediaLocator locator;
	Player player;
	FormatControl formatControl;
	public MyCam(){
		try{
			
			Vector<CaptureDeviceInfo> list = CaptureDeviceManager.getDeviceList ( null );
			
			// Iterate list 
			for(CaptureDeviceInfo temp : list){
				
				if(temp.getName().startsWith("vfw:")){

					
					
					cam = temp;
					System.out.println("Selected : "+cam.getName().substring(4));
					break;
				}
			}

			System.out.println("Loading ...");
			
			locator = cam.getLocator();

			if(locator != null){

				
				player = Manager.createRealizedPlayer(locator);

				if(player != null){
					
					
					player.start();
					
					
					JFrame f = new JFrame();
					f.setTitle("Test Webcam");
					f.setLayout(new BorderLayout());
					
					
					f.add(player.getVisualComponent(), BorderLayout.CENTER);
					f.pack(); 
					f.setVisible(true);

				}

			}

		}catch(Exception e){
			e.printStackTrace();
		}

	}

	public static void main(String[] args) {
		new MyCam();
	}
}

Open in new window

0
 

Author Comment

by:sargent240
ID: 39290375
does this code require the jmf libraries?
0
 
LVL 16

Expert Comment

by:krakatoa
ID: 39290605
I reckon so, yes.
0
 

Author Comment

by:sargent240
ID: 39300214
Got it - Thanks
0
 
LVL 16

Expert Comment

by:krakatoa
ID: 39300681
Good. ;)
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
This video teaches viewers about errors in exception handling.

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now