Click here to Skip to main content
15,897,291 members
Home / Discussions / Java
   

Java

 
GeneralRe: javax,microedition does any one have it ? Pin
williamroma28-Mar-11 23:51
williamroma28-Mar-11 23:51 
GeneralRe: javax,microedition does any one have it ? Pin
TorstenH.29-Mar-11 20:00
TorstenH.29-Mar-11 20:00 
Questionerror with recording the file Pin
jayashree.v28-Mar-11 3:44
jayashree.v28-Mar-11 3:44 
AnswerRe: error with recording the file Pin
TorstenH.28-Mar-11 3:52
TorstenH.28-Mar-11 3:52 
GeneralRe: error with recording the file Pin
jayashree.v28-Mar-11 5:18
jayashree.v28-Mar-11 5:18 
GeneralRe: error with recording the file Pin
jayashree.v28-Mar-11 5:26
jayashree.v28-Mar-11 5:26 
GeneralRe: error with recording the file Pin
TorstenH.28-Mar-11 19:39
TorstenH.28-Mar-11 19:39 
QuestionWebCam record in java Pin
Fatema gabr27-Mar-11 11:34
Fatema gabr27-Mar-11 11:34 
Hi guys,i am asking about webcam video recording thru java,i`ve tried this code but i get this output> Video Capture failed after approximately 0 seconds.
The code consists of 2 files web.java and location2location.java,Can anybody help me about that??thnxxx

import javax.swing.*;
import javax.swing.event.*;
import java.io.*;
import javax.media.*;
import javax.media.format.*;
import javax.media.util.*;
import javax.media.control.*;
import javax.media.protocol.*;
import java.util.*;
import java.awt.*;
import java.awt.image.*;
import java.awt.event.*;
import com.sun.image.codec.jpeg.*;

import javax.imageio.ImageIO; 
import java.awt.image.BufferedImage;

public class Web extends Panel implements ActionListener 
{
  public static Player player = null;
  public CaptureDeviceInfo di = null;
  public MediaLocator ml = null;
  public JButton capture1 = null;
  public Buffer buf = null;
  public Image img = null;
  public VideoFormat vf = null;
  public BufferToImage btoi = null;
  public ImagePanel imgpanel = null;
  public MediaLocator dl;
  String destinationName = null;
  public double duration = 10;
  public int waitFor = 0;
  public Vector devices;
  public static final Format VIDEO_FORMAT = new VideoFormat(VideoFormat.CINEPAK);
  public Location2Location capture;
  public Format[] formats = new Format[1];
  public ContentDescriptor videoContainer = new ContentDescriptor(FileTypeDescriptor.MSVIDEO);
  public ContentDescriptor container = null;
	
//    public boolean useKnownDevices = false;
	
 
  public Web() 
  {
    setLayout(new BorderLayout());
    setSize(320,550);
 
    imgpanel = new ImagePanel();
    capture1 = new JButton("Capture1");
    capture1.addActionListener(this);
 
    String str1 = "vfw:Logitech USB Video Camera:0";
    String str2 = "vfw:Microsoft WDM Image Capture (Win32):0";
    di = CaptureDeviceManager.getDevice(str2);
    ml = new MediaLocator("vfw://0");
    
    String DEFAULT_VIDEO_NAME = "captured.avi";
	String VIDEO = "video";
	String selected = VIDEO;
	
 	//ml = di.getLocator();
	formats[0] = VIDEO_FORMAT;
	if (destinationName==null)
	destinationName = DEFAULT_VIDEO_NAME;
	container = videoContainer;
	
	
	
	dl = new MediaLocator(destinationName);
		System.out.println("Configuring for capture. Please wait.");
		capture = new Location2Location(ml,
		dl,formats,container,1.0);
		
		System.out.println("Started recording " + duration +
		" seconds of " + selected + " ...");
		capture.setStopTime(new Time(duration));
		if (waitFor==0)
		waitFor = (int)(4000*duration);
		else
		waitFor *= 1000;
		int waited = capture.transfer(waitFor);
		

		int state = capture.getState();
		if (state==Location2Location.FINISHED)
		System.out.println(selected + " capture successful " +
		"in approximately " + ((int)((waited+500)/1000)) +
		" seconds. Data written to " + destinationName);
		else if (state==Location2Location.FAILED)
		System.out.println(selected + " capture failed " +
		"after approximately " + ((int)((waited+500)/1000)) +
		" seconds");
		else {
		System.out.println(selected + " capture still ongoing " +
		"after approximately " + ((int)((waited+500)/1000)) +
		" seconds");
		System.out.println("Process likely to have failed");
		}
		
		System.exit(0);	


Location2Location(MediaLocator sourceLocation,
MediaLocator destinationLocation, Format[] outputFormats,
ContentDescriptor outputContainer, double rate) {

//////////////////////////////////////////////
// Construct the processor for the transcoding
//////////////////////////////////////////////
state = TRANSLATING;
sinkLocation = destinationLocation;
try {
if (sourceLocation==null)
model = new ProcessorModel(outputFormats,outputContainer);
else
model = new ProcessorModel(sourceLocation,
outputFormats,outputContainer);
processor = Manager.createRealizedProcessor(model);
}
catch (Exception e) {
state = FAILED;
return;
}

translationRate = processor.setRate((float)Math.abs(rate));
processor.addControllerListener(this);

////////////////////////////////////////////////////////////
// Construct the DataSink and employ an anonymous class as
// a DataSink listener in order that the end of transfer
// (completion of task) can be detected.
///////////////////////////////////////////////////////////
source = processor.getDataOutput();
try {
sink = Manager.createDataSink(source,sinkLocation);
}
catch (Exception sinkException) {
state = FAILED;
processor.removeControllerListener(this);
processor.close();
processor = null;
return;
}
sink.addDataSinkListener(new DataSinkListener() {
public void dataSinkUpdate(DataSinkEvent e) {
if (e instanceof EndOfStreamEvent) {
sink.close();
source.disconnect();
if (state!=FAILED)
state = FINISHED;
}
else if (e instanceof DataSinkErrorEvent) {
if (sink!=null)
sink.close();
if (source!=null)
source.disconnect();
state = FAILED;
}
}
});
// Start the transcoding
processor.start();
}


/***************************************************************
* Alternate constructor: source and destination specified as
* Strings, and no rate provided (hence rate of 1.0)
****************************************************************/
Location2Location(String sourceName, String destinationName,
Format[] outputFormats, ContentDescriptor outputContainer) {

this(new MediaLocator(sourceName), new MediaLocator(destinationName),
outputFormats, outputContainer);
}


/****************************************************************
* Alternate constructor: No rate specified therefore rate of 1.0
*****************************************************************/
Location2Location(MediaLocator sourceLocation,
MediaLocator destinationLocation, Format[] outputFormats,
ContentDescriptor outputContainer) {

this(sourceLocation,destinationLocation,outputFormats,outputContainer,1.0f);
}


/***************************************************************
* Alternate constructor: source and destination specified as
* Strings.
****************************************************************/
Location2Location(String sourceName, String destinationName,
Format[] outputFormats, ContentDescriptor outputContainer,
double rate) {

this(new MediaLocator(sourceName), new MediaLocator(destinationName),
outputFormats, outputContainer, rate);
}


public synchronized void controllerUpdate(ControllerEvent e) {

if (state==FAILED)
return;

// Transcoding complete.
if (e instanceof StopEvent) {
processor.removeControllerListener(this);
processor.close();
if (state==TRANSLATING)
state = TRANSFERRING;
}
// Transcoding failed.
else if (e instanceof ControllerErrorEvent) {
processor.removeControllerListener(this);
processor.close();
state = FAILED;
}
}

public int transfer(int timeOut) {

// Can't initiate: Processor already failed to transcode
////////////////////////////////////////////////////////
if (state==FAILED)
return -1;

// Start the DataSink
//////////////////////
try {
sink.open();
sink.start();
}
catch (Exception e) {
state = FAILED;
return -1;
}
if (state==TRANSLATING)
state = TRANSFERRING;
if (timeOut<=0)
return timeOut;

// Wait till the process is complete, failed, or the
// prescribed time has passed.
/////////////////////////////////////////////////////
int waited = 0;
while (state!=FAILED && state!=FINISHED && waited<timeOut) {
try { Thread.sleep(WAIT_PERIOD); }
catch (InterruptedException ie) { }
waited += WAIT_PERIOD;
}
return waited;
}

Questionhow to record a video in java? Pin
Fatema gabr27-Mar-11 11:03
Fatema gabr27-Mar-11 11:03 
AnswerRe: how to record a video in java? Pin
ankitjoshi245-Apr-11 10:21
ankitjoshi245-Apr-11 10:21 
AnswerRe: how to record a video in java? Pin
Adrabi Abderrahim12-Apr-11 11:39
Adrabi Abderrahim12-Apr-11 11:39 
AnswerRe: how to record a video in java? Pin
csanuragjain16-Apr-11 21:59
csanuragjain16-Apr-11 21:59 
Questionhow to open a website when i press a button in Java Pin
williamroma26-Mar-11 14:22
williamroma26-Mar-11 14:22 
AnswerRe: how to open a website when i press a button in Java Pin
Richard MacCutchan26-Mar-11 21:53
mveRichard MacCutchan26-Mar-11 21:53 
AnswerRe: how to open a website when i press a button in Java Pin
DaveAuld26-Mar-11 22:41
professionalDaveAuld26-Mar-11 22:41 
GeneralRe: how to open a website when i press a button in Java Pin
Richard MacCutchan27-Mar-11 0:52
mveRichard MacCutchan27-Mar-11 0:52 
AnswerRe: how to open a website when i press a button in Java Pin
TorstenH.28-Mar-11 1:19
TorstenH.28-Mar-11 1:19 
QuestionSwing JDialog bug? [modified] Pin
amit ofer26-Mar-11 1:03
amit ofer26-Mar-11 1:03 
AnswerRe: Swing JDialog bug? Pin
TorstenH.28-Mar-11 1:25
TorstenH.28-Mar-11 1:25 
QuestionCrash in java.exe Pin
schki0225-Mar-11 13:31
schki0225-Mar-11 13:31 
AnswerRe: Crash in java.exe Pin
TorstenH.28-Mar-11 1:16
TorstenH.28-Mar-11 1:16 
Questioncolor fade animation for grid cells in swing Pin
amit ofer25-Mar-11 5:30
amit ofer25-Mar-11 5:30 
QuestionGluing JLabels to a contentPane Pin
kurt124-Mar-11 12:30
kurt124-Mar-11 12:30 
AnswerRe: Gluing JLabels to a contentPane Pin
JP_Rocks27-Mar-11 1:07
JP_Rocks27-Mar-11 1:07 
Questionusing scroll in java GUI Pin
williamroma23-Mar-11 2:23
williamroma23-Mar-11 2:23 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.