Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Java video class

Posted on 2013-06-30
5
Medium Priority
?
430 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 2000 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
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 if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
Suggested Courses

730 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