I'm not skilled at Java at all so I could really use your help. I'm trying to read the duration and bit rate from an mp3 file. I'm using a java library called "mp3spi" from http://www.javazoom.net/mp3spi/documents.html.
So var I've been able to determine that these objects exist:
<cfset AudioFormat = createObject("java", "org.tritonus.share.sampled.TAudioFormat")>
<cfset AudioFileFormat = createObject("java", "org.tritonus.share.sampled.file.TAudioFileFormat")>
<cfset AudioFileReader = createObject("java", "javax.sound.sampled.spi.AudioFileReader")>
I'm having trouble with the following code and converting it to ColdFusion:
File file = new File("filename.mp3");
AudioFileFormat baseFileFormat = new MpegAudioFileReader().getAudioFileFormat(file);
Map properties = baseFileFormat.properties();
Long duration = (Long) properties.get("duration");
I've tried several ways of setting the above variables, but I keep getting an error that either MpegAudioFileReader or getAudioFileFormat doesn't exist. However when I dump the variables I used to create the Java objects, they do exist.
Here is what I have:
<cfscript>
mp3file = FileOpen(ExpandPath("./") & originalfile, "readBinary");
baseFileFormat = AudioFileReader.getAudioFileFormat(mp3file);
properties = baseFileFormat.properties();
duration = properties.get("duration");
</cfscript>
Either there are no methods with the specified method name and argument types or the xxxx method is overloaded with argument types that ColdFusion cannot decipher reliably.". So it often means the method you are calling DOES exist, you are just passing in the wrong argument type. The code above is passing binary togetAudioFileFormat(), when it requires ajava.io.Fileobject instead. Hence the error. See @Adam's example for how to create a File object (but use an absolute path, not just the file name)