Solved

Java video class

Posted on 2013-06-30
5
413 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

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
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:

728 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