I’m new to Juce and am trying to read metadata from an mp3 file. I get the error that the juce::AudioFormat has no appropriate default constructor available. How do I fix this?
class PlaylistComponent : public juce::Component,
public TableListBoxModel,
public Button::Listener,
public AudioSource,
public AudioFormat
You don’t need inheritance at all to read audio file metadatas. In principle code like the following should work, but at least a random mp3 file I picked up from my drive didn’t produce any metadata keys/values…But looking at the file with Foobar2000, there definitely is metadata. The Juce mp3 metadata handling might be broken/limited in some manner.
juce::AudioFormatManager aman;
aman.registerBasicFormats();
juce::File f("D:\\foo.mp3");
auto reader = aman.createReaderFor(f);
if (reader)
{
auto keys = reader->metadataValues.getAllKeys();
for (auto& k : keys)
{
DBG(k << reader->metadataValues.getValue(k,""));
}
delete reader;
}
On Windows you need to use \\ instead of \ for the file paths in source code. But in any case, it does look like Juce doesn’t actually even support the typical metadata stuff in mp3 files.
OK I added that and it does print out “reader opened: …” which means my reader is opened but it doesn’t seem to print out the metadata. And yes I added jassert
I think if the reader is opened correctly and there is nothing in the metadataValues, then it seems JUCE is not reading the metadata or the mp3 has no metadata.
This is the code I’m using. The file path is Z:\WF\Music\example.mp3. I checked that the mp3 has metadata. Do you see anything wrong with the code? It only prints out reader opened but doesn’t print out the metadata.
formatManager.registerBasicFormats();
auto file = juce::File("Z:").getChildFile("WD").getChildFile("Music").getChildFile("example.mp3");
jassert(file.existsAsFile());
auto reader = formatManager.createReaderFor(file);
if (reader)
{
DBG("reader opened: " << file.getFullPathName());
for (auto& key : reader->metadataValues.getAllKeys())
{
DBG("Value: " + reader->metadataValues.getValue(key, ""));
}
delete reader;
}
else
{
DBG("reader not open: " << file.getFullPathName());
}