So I’m trialing the FileDragAndDropTarget class… dragging an audio file, inside **bool** AudioTrack::isInterestedInFileDrag( **const** juce::StringArray &files) I would like to check if the incoming file’s format matches the registered formats.
Currently I’m doing a simple check from the filename
And then checking against that, which works however when dragging in a random file it obviously crashes because the ‘createReaderFor(file)’ has asserted that the file format does not contain in the listed formats.
Maybe I’m over complicating this. Does anyone have any initial format checks against the known registered formats?
If you call createReaderFor(), it actually reads the beginning of the file, and checks whether there’s e.g. a valid WAV header. But if you just want to check for the file extension (.wav, .aiff, etc.) this would work:
Just a sidenote: If you’re calling createReaderFor(), you’re responsible for deleting the returned reader. A good way to do this is to write unique_ptr<AudioFormatReader> reader(formatManager.createReaderFor(file));.
If I did want to create an AudioFormatReader object in the header file,
std::unique_ptr<AudioFormatReader> audioReader;
then instantiate it inside the **bool** AudioTrack::isInterestedInFileDrag( **const** juce::StringArray &files) function, so I can refer to it throughout the application… how would I go about this?
This is what I thought should work: audioReader.reset( new AudioFormatReader(formatManager.createReaderFor(file))); but doesn’t.