我是一个有用的助手,可以为您翻译文本。以下是您需要翻译的内容:
我遇到了以下代码的问题,需要将其转换为ColdFusion代码:
我尝试了几种设置上述变量的方法,但是我一直收到错误消息,提示MpegAudioFileReader或getAudioFileFormat不存在。然而,当我转储用于创建Java对象的变量时,它们确实存在。
以下是我的代码:
我完全不擅长Java,所以我真的需要您的帮助。我正在尝试从mp3文件中读取持续时间和比特率。我正在使用名为“mp3spi”的Java库,来源于http://www.javazoom.net/mp3spi/documents.html。
到目前为止,我已经确定这些对象存在:
<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")>
我遇到了以下代码的问题,需要将其转换为ColdFusion代码:
我遇到了以下代码的问题,需要将其转换为ColdFusion代码:
File file = new File("filename.mp3");
AudioFileFormat baseFileFormat = new MpegAudioFileReader().getAudioFileFormat(file);
Map properties = baseFileFormat.properties();
Long duration = (Long) properties.get("duration");
我尝试了几种设置上述变量的方法,但是我一直收到错误消息,提示MpegAudioFileReader或getAudioFileFormat不存在。然而,当我转储用于创建Java对象的变量时,它们确实存在。
以下是我的代码:
<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.
”。这通常意味着你调用的方法确实存在,只是传入了错误的参数类型。以上代码将二进制数据传递给了getAudioFileFormat()
方法,而该方法需要一个java.io.File
对象作为参数。因此出现了错误。请参考@Adam的示例,了解如何创建一个File对象(但要使用绝对路径,而不仅仅是文件名)。 - Leigh