Metadata Value from Audio Files


#1

Hello.

I am having some issues with extracting metadata values from audio files i.e Artist, Song name etc.
I have tried using an AudioFormatReader and passing the file into it. The format reader then has a String Array within it called “metadata”, but when I access this, there is only NULL within it.

Is anyone able to give me a guide on how to get this information?

Many thanks


#2

Not all audio formats support meta data. So to help you you might tell us which format you try to read.
From the docs:

A set of metadata values that the reader has pulled out of the stream.
Exactly what these values are depends on the format, so you can check
out the format implementation code to see what kind of stuff they
understand.


#3

I am wanting to extract metadata from .Aiff, .Aif and Mp3.


#4

Each format has their own identifier for what that could possibly be. Here are a couple examples:

You would get the value by using the identifier as a key in the string pair array from the audio format reader instance of the desired audio file.


#5

Ok, I think I understand.

I’ve tried to setup an AiffAudioFormat. Not sure I’m getting how to access the metadata.

Here is my code:

while (directoryIterator.next())
{
    musicFiles[numFilesInDirectory].filePointer = directoryIterator.getFile();
    musicFiles[numFilesInDirectory].songID = numFilesInDirectory + 1;

    if (musicFiles[numFilesInDirectory].filePointer.getFileExtension() == ".aiff") {
        
        AiffAudioFormat aiffFormat;
        aiffFormat.createMemoryMappedReader(directoryIterator.getFile());
        String artistName;
        artistName = aiffFormat.appleTag;
    }
    numFilesInDirectory++;
}

Any help would be appreciated


#6

I would suggest using the AudioFormatManager instead of trying the extension manually

I’ll try something out of my head:

AudioFormatManager formatManager;
formatManager.registerBasicFormats();

// in the loop:
ScopedPointer<AudioFormatReader> reader = formatManager.createReaderFor (directoryIterator.getFile());
if (reader) {
    for (String key : reader->metadataValues.getAllKeys()) {
        DBG ("Key: " + key + " value: " + reader->metadataValues.getValue (key, "unknown"));
    }
}

Havent tested this, but it might work like that…


#7

+1 to daniel’s suggestion! It really helps keep code as simple and straightforward as possible.


#8

I’ve had a look at this code, and I have the same issue where the reader->metadataValues still returns ‘NULL’.

The files I am using definitely have metadata embedded. Should it matter what version of ID tag I am using within the files?


#9

Well, if you go by daniel’s suggestion and work the metadata values this way and get empty strings, then I’d assume one two things: the file didn’t have the data you’re looking for or the decoder didn’t understand it.

//Lets assume you loaded an AIFF file:
DBG("Result of file's Apple tag: " + reader->metadataValues[AiffAudioFormat::appleTag]);

To me, it looks like your metadata values object is empty - seems like it needs investigation into the decoder (assuming you know there really is data).


#10

Metadata for wav files in particular is a bit of a black hole. We’ve been looking at using metadata for a new product and tried to find a standard format. Hah! Unless you’re putting it there yourself then be very sceptical about what you can expect to get out. The biggest player in the market is Soundminer and they have their own proprietary, encoded format…