Java JMF problem med at skrive til fil ved hjælp af DataSink
Hej, jeg er ved at lave en lille optager og afspiller til lyd i JMF. Jeg har ikke problemer med at opfange (capture) lyden, afspille den, sende den til en anden computer (RTP), men jeg kan ikke få oprettet en DataSink, der tager en MediaLocator indeholdende en File reference som output. For at vise problemet har jeg taget et lille stykke kode (fra IBM's tutorial) som bruger en DataSink til at transmittere lyd og ændret idet så det burde skrive til en Fil i stedet.Jeg får fejlmeddelsesen:
javax.media.NoDataSinkException: Cannot find a DataSink for: com.sun.media.multi
plexer.RawBufferMux$RawBufferDataSource@1b15692
at javax.media.Manager.createDataSink(Manager.java:1894)
at MediaTransmitter.setDataSource(MediaTransmitter.java:103)
at MILETransSaver.main(MILETransSaver.java:146)
Her er koden:
import javax.media.*;
import javax.media.control.*;
import javax.media.protocol.*;
import javax.media.format.*;
import java.io.IOException;
import java.io.File;
public class MILETransSaver {
private MediaLocator mediaLocator = null;
private DataSink dataSink = null;
Processor mediaProcessor = null;
private static final Format[] FORMATS = new Format[] {
new AudioFormat(AudioFormat.MPEG)};
private static final ContentDescriptor CONTENT_DESCRIPTOR =
new ContentDescriptor(ContentDescriptor.RAW);
public MILETransSaver(MediaLocator locator) {
mediaLocator = locator;
}
public void startTransmitting() throws IOException {
// start the processor
mediaProcessor.start();
// open and start the data sink
dataSink.open();
dataSink.start();
}
public void stopTransmitting() throws IOException {
// stop and close the data sink
dataSink.stop();
dataSink.close();
// stop and close the processor
mediaProcessor.stop();
mediaProcessor.close();
}
public void setDataSource(DataSource ds) throws IOException,
NoProcessorException, CannotRealizeException, NoDataSinkException {
mediaProcessor = Manager.createRealizedProcessor(
new ProcessorModel(ds, FORMATS, CONTENT_DESCRIPTOR));
dataSink = Manager.createDataSink(mediaProcessor.getDataOutput(),mediaLocator);
}
public static void printUsage() {
System.out.println("Usage: java MediaTransmitter mediaLocator " +
"mediaFile");
System.out.println(" example: java MediaTransmitter " +
"rtp://192.168.1.72:49150/audio mysong.mp3");
System.out.println(" example: java MediaTransmitter " +
"rtp://192.168.1.255:49150/audio mysong.mp3");
}
public static void main(String[] args) {
try {
if (args.length == 2) {
File destFile = new File(args[1]);
MediaLocator locator = new MediaLocator(destFile.toURL());
MediaTransmitter transmitter = new MediaTransmitter(locator);
System.out.println("-> Created media locator: '" +
locator + "'");
File mediaFile = new File(args[0]);
DataSource source = Manager.createDataSource(
new MediaLocator(mediaFile.toURL()));
System.out.println("-> Created data source: '" +
mediaFile.getAbsolutePath() + "'");
// set the data source.
transmitter.setDataSource(source);
System.out.println("-> Set the data source on the transmitter");
// start transmitting the file over the network.
transmitter.startTransmitting();
System.out.println("-> Transmitting...");
System.out.println(" Press the Enter key to exit");
// wait for the user to press Enter to proceed and exit.
System.in.read();
System.out.println("-> Exiting");
transmitter.stopTransmitting();
} else {
printUsage();
}
} catch (Throwable t) {
t.printStackTrace();
}
System.exit(0);
}
}