Selecting resources using BinaryData and playfile


#1

Hi all,
Is it possible to select a resource from this array in the BinaryData namespace ?

I am trying to figure out how to play an mp3 by passing a number to an array of resources.
Do I need to initialize an array in the constructor or can I just do something like this?

    void playfile(const void * sourceData, size_t sourceDataSize)
    {
    AudioFormatReader* reader = formatManager.createReaderFor( new MemoryInputStream(sourceData, sourceDataSize, false));
    if (reader != nullptr)
    {
        ScopedPointer<AudioFormatReaderSource> newSource = new AudioFormatReaderSource (reader, true);
        transportSource.setSource (newSource, 0, nullptr, reader->sampleRate);
        playButton.setEnabled (true);
        readerSource = newSource.release();
    }
    if (reader == nullptr)
    {
        playButton.setEnabled (false);
    }
    transportSource.setPosition (0.0);
    changeState (Starting);
    }
    
int main()
{
int note = 1;
playfile(BinaryData::getNamedResource(BinaryData::namedResourceList[note]));
}

Any replies from this JUCE and C++ newbie would be greatly appreciated …
Sean


#2

When pasting code, please use a 4-space indent or put triple-backticks around it!


#3

thanks!