Hi,
On Windows, I’m unable to create reader from AudioFormatManager as it doesn’t print “Created Reader” which makes me think there is something wrong with “file:\\Clocks.mp3”. File is located in the same directory as MainComponent.cpp where the following code exists. Can you please let me know how to specify file location?
void MainComponent::prepareToPlay (int samplesPerBlockExpected, double sampleRate)
{
//To make formatManager ready to read formats
formatManager.registerBasicFormats();
URL audioURL{"file:\\\Clocks.mp3"};
//audioURL is converted into inputstream
//that is passed to audio formatManager
//that creates a reader
auto* reader = formatManager.createReaderFor(audioURL.createInputStream(false));
DBG("outside");
if (reader != nullptr) //good file
{
DBG("Created Reader");
}
}
I tried to change location format but doesn’t work
Listed file formats
for (int i = 0; i < formatManager.getNumKnownFormats(); i++) {
std::string s = formatManager.getKnownFormat(i)->getFormatName().toStdString();
DBG(s);
}
output was
WAV file
AIFF file
FLAC file
Ogg-Vorbis file
Windows Media
Since there was no mp3 format in the list so I converted mp3 file to .wav file.
I tried the following but still doesn’t work. File location is in C:\Song\Clocks.wav
//To make formatManager ready to read formats
formatManager.registerBasicFormats();
juce::URL audioURL{"file:///C:\Song/Clocks.wav"};
DBG(audioURL.getFileName());
//DBG(BoolToString(audioURL.isLocalFile()));
//audioURL is converted into inputstream
//that is passed to audio formatManager
//that creates a reader
juce::AudioFormatReader* reader = formatManager.createReaderFor(audioURL.createInputStream(false));
DBG("outside");
if (reader != nullptr) //good file
{
DBG("Created Reader");
}
Specifying file format as the following solved the issue.
juce::URL audioURL{"file:///C:\\Song/Clocks.wav"};