Skip to main content
Inspiring
March 22, 2026
Answered

AudioFileIO's getTag() fails

  • March 22, 2026
  • 2 replies
  • 38 views

I am trying to use org.jaudiotagger.audio.AudioFileIO to read some tags in mp3 files.  The following lines work correctly:

 fileObj = createObject("java", "java.io.File").init(lsFileNameWithPath);
audioFileIO = createObject("java", "org.jaudiotagger.audio.AudioFileIO");
audioFile = audioFileIO.read(fileObj);
audioHeader = audioFile.getAudioHeader();
bitrate = audioHeader.getBitRate();
writeOutput("The audio file bitrate is: " & bitrate);
writeOutput(AudioHeader);

but If I try anything with tags such as:
Tag tag = audioFile.getTag();              or
lsArtist = audioFile.getTag().getFirst(FieldKey.ARTIST);
I get error messages.  In the first case the error message is “ Variable TAG is undefined.“ and in the second case the error message is “ Variable FIELDKEY is undefined”

Any suggestions as to what I am doing wrong?

    Correct answer BKBK

    As to the question of what you are doing wrong, Charlie has provided a suggestion. Namely that it is incorrect to import Java verbatim into ColdFusion using

    Tag tag = audioFile.getTag();

    I agree. As he says, cfjava would be handy if you wanted to use Java code directly in ColdFusion to create Java classes.

     

    However, what I want to suggest are ways to ensure that the code you have shown works:

    (1)  ColdFusion determines type implicitly. So, you can replace the above line with

    tag = audioFile.getTag();

     

    (2)  On googling org.jaudiotagger.audio  I found the Jaudiotagger library on Github. According to this documentation, FieldKey is a class that represents an enumeration. The keys in FieldKey , such as ALBUM, ARTIST, BARCODE, etc., are static constants. Therefore you could replace

    lsArtist = audioFile.getTag().getFirst(FieldKey.ARTIST);

    with something like

    fieldKey = createobject("java","org.jaudiotagger.tag.FieldKey");
    // use tag instance created earlier
    lsArtist = tag.getFirst(fieldKey.ARTIST);

     
    That’s just a start. Let us know how it goes. We’ll discuss further if and where necessary.

    2 replies

    BKBK
    Community Expert
    BKBKCommunity ExpertCorrect answer
    Community Expert
    March 23, 2026

    As to the question of what you are doing wrong, Charlie has provided a suggestion. Namely that it is incorrect to import Java verbatim into ColdFusion using

    Tag tag = audioFile.getTag();

    I agree. As he says, cfjava would be handy if you wanted to use Java code directly in ColdFusion to create Java classes.

     

    However, what I want to suggest are ways to ensure that the code you have shown works:

    (1)  ColdFusion determines type implicitly. So, you can replace the above line with

    tag = audioFile.getTag();

     

    (2)  On googling org.jaudiotagger.audio  I found the Jaudiotagger library on Github. According to this documentation, FieldKey is a class that represents an enumeration. The keys in FieldKey , such as ALBUM, ARTIST, BARCODE, etc., are static constants. Therefore you could replace

    lsArtist = audioFile.getTag().getFirst(FieldKey.ARTIST);

    with something like

    fieldKey = createobject("java","org.jaudiotagger.tag.FieldKey");
    // use tag instance created earlier
    lsArtist = tag.getFirst(fieldKey.ARTIST);

     
    That’s just a start. Let us know how it goes. We’ll discuss further if and where necessary.

    Inspiring
    March 23, 2026

    It worked absolutely perfectly!  Just exactly what I wanted.  I will postpone getting started with JAVA for another day.  Thanks so much! 

    BKBK
    Community Expert
    Community Expert
    March 23, 2026

    Hi ​@fredp60157821 , Thanks for the update.

    I am glad to hear that it worked.

    Charlie Arehart
    Community Expert
    Community Expert
    March 23, 2026

    The two lines in error are Java rather than cfml, which your first 7 lines clearly are. You can't just drop Java into cfml. As your first 7 lines reflect, you can instantiate Java objects and use them--via cfml that refers to the objects. 

     

    The first error is that you have "Tag tag". That first reference would (in Java) define the class of the object. Cf doesn't support that. (That's why it's undefined. You could prove that by changing the first to be tag1, and see if the error changes to refer to that.) 

     

    The second error is similar: your reference to FieldKey in that second line would be a "field" in Java...and cf against doesn't support that by such a line of cfml. (It is possible to declare and use fields within a Java class. You can find more on that in docs, online, or via AI).

     

    Finally, note that since cf2021 it's been possible to actually use pure Java within cfml, by way of the cfjava tag. Again, you can find more on that if interested.

     

    Let us know how if this helps. 

    /Charlie (troubleshooter, carehart. org)
    Inspiring
    March 23, 2026

    Thank you so much for taking the time to help me on this.  I know Cf reasonably well, but no nothing about Java.  The only line I really care about is 

    lsArtist = audioFile.getTag().getFirst(FieldKey.ARTIST);

    so I can get the artist’s name for an mp3 file.  If I understand you correctly, what I have to do is to first learn Java enough to get this to work in java and then somehow place that code in a CFJAVA tag.  I’ll see if I can learn just enough Java to get this done.  Thanks again.

    Charlie Arehart
    Community Expert
    Community Expert
    March 23, 2026

    BKBK has helpfully come through with the specific Java class (and cfml) you needed for that challenge. To be clear, I was pointing out that you could EITHER use Java (with cfjava) OR write cfml to access the fields (like he's offered).

     

    And I'd mentioned how the cf docs could have helped. If you're going to do more interaction with Java in cfml (which had been possible for 20 years before cfjava was added), that's covered in docs that some find more challenging to discover.

     

    See the cf development guide (not the cfml reference), such as:

     

    https://helpx.adobe.com/coldfusion/developing-applications/using-web-elements-and-external-objects/integrating-jee-and-java-elements-in-cfml-applications/using-java-objects.html

     

    And this one even showed specifically accessing such "fields" from a Java objects:

     

     https://helpx.adobe.com/coldfusion/cfml-reference/coldfusion-tags/tags-m-o/cfobject-java-or-ejb-object.html

     

    Offering all that for you (as you proceed beyond this one need) as well as for other readers who may find this thread in the future. 

    /Charlie (troubleshooter, carehart. org)