我正在尝试使用以下代码将wav文件转换为mp3格式。创建了一个mp3文件,但它是没有任何内容的空白文件。可能导致这种情况的任何想法。
Format[] FORMATS = new Format[] { new AudioFormat(
AudioFormat.LINEAR) };
String srcFilePath = "C:" + File.separator + "Users"
+ File.separator + "vkiran" + File.separator + "Desktop"
+ File.separator + "test" + File.separator + "4a714ea2.wav";
String mp3FilePath = "C:" + File.separator + "Users"
+ File.separator + "vkiran" + File.separator + "Desktop"
+ File.separator + "test" + File.separator + "4a714ea2.mp3";
File srcFile = new File(srcFilePath);
File destFile = new File(mp3FilePath);
MediaLocator source = new MediaLocator(srcFile.toURL());
DataSource d = Manager.createDataSource(source);
ContentDescriptor cd = new ContentDescriptor(
FileTypeDescriptor.MPEG_AUDIO);
Processor p = Manager.createRealizedProcessor(new ProcessorModel(d,
FORMATS, cd));
p.configure();
System.out.println((p.getDuration()).getSeconds());
MediaLocator destination = new MediaLocator(destFile.toURL());
DataSource ds = p.getDataOutput();
DataSink sink = Manager.createDataSink(p.getDataOutput(),
destination);
sink.open();
sink.start();
sink.stop();
sink.close();
p.stop();
p.close();