Convert Java code to ColdFusion

I do not speak Java at all, so I really could use your help. I am trying to read the duration and bit rate from an mp3 file. I am using a java library called "mp3spi" from http://www.javazoom.net/mp3spi/documents.html .

So, var, I was 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 am having problems 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 tried several ways to set the above variables, but I keep getting an error that MpegAudioFileReader or getAudioFileFormat does not exist. However, when I reset the variables that I used to create the Java objects, they exist.

Here is what I have:

<cfscript>
    mp3file = FileOpen(ExpandPath("./") & originalfile, "readBinary");
    baseFileFormat = AudioFileReader.getAudioFileFormat(mp3file);
    properties = baseFileFormat.properties();
    duration = properties.get("duration");
</cfscript>
+4
2

, , coupla.

File file = new File("filename.mp3");

, , , , CFML -, LHS, createObject() Java, . CF Java, File. :

mp3File = createObject("java", "java.io.File").init("filename.mp3");

( @Leigh , File CFML, ! mp3File )

... . Java, , , - (long) ..

, , ( - ). , " ". , ( , StackOverflow).

+6

. Java, , , init(). ...

mp3file = createObject("java", "java.io.File").init("filename.mp3");
baseFileFormat = createObject("java", "path.to.MpegAudioFileReader").init().getAudioFileFormat(mp3file);
properties = baseFileFormat.properties();
duration = properties.get("duration");

, . ColdFusion, , , , ColdFusion Hibernate, Java . , , ColdFusion, .

+5

All Articles