Java - Problema con JMF

 
Vista:

Problema con JMF

Publicado por Jose David (5 intervenciones) el 12/08/2007 22:15:04
Si alguien me puede ayudar, estoy intentando atraves de JMF capturar audio a traves de un microfono, pero al intentar obtener del datasink me genera una excepcion. Este es el error:
Cannot find a DataSink for: com.sun.media.multiplexer.BasicMux$BasicMuxDataSource@f9f9d8

Estoy trabajando con un microfono de esos que vienen con los auriculares por si esto sirve de algo.
Este es el codigo fuente:

/**
* @(#)JMFAudio.java
*
*
* @author
* @version 1.00 2007/8/11
*/

import java.awt.*;
import java.util.*;
import javax.media.format.*;
import javax.media.*;
import java.io.*;
import javax.media.protocol.*;
import javax.media.control.*;

public class JMFAudio {

CaptureDeviceInfo di;
Processor p;
StateHelper sh;
/** Initialization method that will be called after the applet is loaded
* into the browser.
*/
public void init() {

Vector dispositivos = CaptureDeviceManager.getDeviceList(new AudioFormat("linear", 44100, 16, 2));
/*for(int i =0; i < dispositivos.size(); i++){
di = (CaptureDeviceInfo)dispositivos.get(i);
System.out.println("Ok,dispositivo "+di.getName());
}*/
if(dispositivos.size() > 0)
di = (CaptureDeviceInfo)dispositivos.firstElement();


System.out.println("Ok");

try{
MediaLocator loc = di.getLocator();
System.out.println("protocolo "+loc.getProtocol());
System.out.println("remainder "+loc.getRemainder());
//System.out.println("URL "+loc.getURL());
System.out.println("EXT "+loc.toExternalForm());
System.out.println("STRING "+loc.toString());

p = Manager.createProcessor(loc);
sh = new StateHelper(p);
System.out.println("Ok");
FileOutputStream out = new FileOutputStream("sonido.wav");

}catch(IOException e){
System.out.println("Error IO "+e.getMessage());
System.exit(-1);
}
catch(NoPlayerException ne){
System.out.println("Error No Player "+ne.getMessage());
System.exit(-1);

}

// Configure the processor
if (!sh.configure(10000))
System.exit(-1);
// Set the output content type and realize the processor
p.setContentDescriptor(new FileTypeDescriptor(FileTypeDescriptor.WAVE));
if (!sh.realize(10000)){
System.out.println("Error !sh.realize");
System.exit(-1);
}

// get the output of the processor
DataSource source = p.getDataOutput();
try{
source.connect();
source.start();
}catch(IOException e){
System.out.println("Error "+e.getMessage());
}
System.out.println("Source "+source);
// create a File protocol MediaLocator with the location of the
// file to which the data is to be written
MediaLocator dest = new MediaLocator("sonido.wav");
// create a datasink to do the file writing & open the sink to
// make sure we can write to it.
DataSink filewriter = null;
try {
//AQUI SUCEDE EL ERROR
filewriter = Manager.createDataSink(source, dest);
filewriter.open();
} catch (NoDataSinkException e) {
System.out.println("Error NoDataSinkException "+e.getMessage());
System.exit(-1);
} catch (IOException e) {
System.out.println("Error IOException "+e.getMessage());
System.exit(-1);
} catch (SecurityException e) {
System.out.println("Error SecurityException "+e.getMessage());
}

// if the Processor implements StreamWriterControl, we can
// call setStreamSizeLimit
// to set a limit on the size of the file that is written.
StreamWriterControl swc = (StreamWriterControl)
p.getControl("javax.media.control.StreamWriterControl");
//set limit to 5MB
if (swc != null)
swc.setStreamSizeLimit(5000000);
// now start the filewriter and processor
try {
filewriter.start();
} catch (IOException e) {
System.exit(-1);
}
// Capture for 5 seconds
sh.playToEndOfMedia(5000);
sh.close();
// Wait for an EndOfStream from the DataSink and close it...
filewriter.close();
}
/*
public void start() {
p.start();
}
public void stop() {
p.stop();
p.deallocate();
}
*/
public void destroy() {
p.close();
}

public static void main(String arg[]){
new JMFAudio().init();
}

/*
public synchronized void controllerUpdate(ControllerEvent event) {
if (event instanceof RealizeCompleteEvent) {
Component comp;
if ((comp = p.getVisualComponent()) != null)
add("Center", comp);
if ((comp = p.getControlPanelComponent()) != null)
add("South", comp);
validate();
}
}*/
}
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder