1 Reply Latest reply on Dec 1, 2013 2:36 PM by BKBK

    Please help me convert this Java code to ColdFusion


      Hello everyone,


      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:

      = FileOpen(ExpandPath("./") & originalfile, "readBinary");
      = AudioFileReader.getAudioFileFormat(mp3file);
      = baseFileFormat.properties();
      = properties.get("duration");

      I can't figure out how to use File, AudioFileFormat, Map, and Long respectively in my cfscript.



      Thank you.


      -- Simone


      Message was edited by: shenry  I'm not asking for someone to write my code for me. I'm saying I don't understand this Java code and I'm getting errors with my own code and can't figure out where I've gone wrong.

        • 1. Re: Please help me convert this Java code to ColdFusion
          BKBK Adobe Community Professional & MVP

          <!--- A search of the web shows that class of MpegAudioFileReader is javazoom.spi.mpeg.sampled.file.MpegAudioFileReader--->

          <cfset mpegAudioFileReader = createObject("java", "javazoom.spi.mpeg.sampled.file.MpegAudioFileReader").init()>


          /* ColdFusion's fileOpen() does not return a Java File object! ColdFusion equivalent of: File file = new File("filename.mp3") */

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


          /*baseFileFormat is of type javax.sound.sampled.AudioFileFormat*/

          baseFileFormat = mpegAudioFileReader.getAudioFileFormat(mp3file)