I've struggled a lot with Java but could not combine a working example of Java .wav to .mp3 converter. This converter will be used in a Java applet so it should depend only on libraries written in pure Java with no underlying C code calls.
Can anyone provide a fully working example?
Thank you
Read your wave file @ http://java.sun.com/javase/technologies/desktop/media/jmf/ and encode to mp3 @ http://openinnowhere.sourceforge.net/lameonj/
As pointed out, lameonj is not a pure java solution. For that the options don't seem so many, but see the other SO question: MP3 Encoding in Java
I use Jump3r to convert wav to mp3 on my project because the html5 player of IE11 can't play wav files.
Jump3r is the simpliest solution found to run inside a tomcat servlet. I wasn't able to integrate others solutions like jave certainly due to the security manager... Jump3r is a pure java program.
Jump3r is available on the maven repository (https://mvnrepository.com/artifact/de.sciss/jump3r/1.0.4) and the sources are available on github (https://github.com/Sciss/jump3r)
To convert a file, you should call the main method (in the following code, I use an inlined version of the main method to catch/throw an IOException if necessary)
private void convertWavFileToMp3File(File source, File target) throws IOException {
String[] mp3Args = { "--preset","standard",
"-q","0",
"-m","s",
source.getAbsolutePath(),
target.getAbsolutePath()
};
(new Main()).run(mp3Args);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With