Solved

Java video class

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

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…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
This video teaches viewers about errors in exception handling.
Suggested Courses

630 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