Solved

Java video class

Posted on 2013-06-30
5
401 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Detect Closed Loops (circles, figure-8s, etc) in PNG Images 6 74
Notify sent to other threads in Java 9 41
java mysql insert application 14 41
Java array sort 10 29
An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

735 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