New User attempting select BinaryResource at random

As explained in the documentation. The range is maximum exclusive. So passing in 2 into that function makes 1 the maximum value and passing in 11 would make 10 the maximum etc.

lovely thanks I suspected that was what was going on !!

I got it to work in a pretty grubby way …

    void playfile(int n)
    {
        AudioFormatReader* reader = formatManager.createReaderFor( new MemoryInputStream(BinaryData::getNamedResource(BinaryData::namedResourceList[n], mp3Size), mp3Size, 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);
    }
    
 
    
    void playButtonClicked()
    {

        int choice1 = Random::getSystemRandom().nextInt(2);


        playfile(choice1);
    }
int mp3Size = 93546;

All the mp3 files I am playing are the same size. I can select the file to play.
Because they are all the same size I can pass the value straight in to the memory input reader .

I still can’t figure out how to get the value of the binary file size based on it’s name and pass it into another function …

It will all work as long as all my samples are the same size so it should work but it still looks a little grubby.

Thanks for all your input I learnt a lot !
Sean

Why are you using the audio files as binary resources to begin with? Why not just use real files from the disk? (I’ve myself pretty much dropped using the binary resources, they are more trouble than I have been willing to deal with…)

I can’t remember the reason !
I started with this
https://www.juce.com/doc/tutorial_playing_sound_files
As I am still learning I ran around until I could get something to work …
I had trouble with the “file” class …
The binary data was a bit easier because I could easily look at the header file and cpp file and figure out what was actually going on …
If all the documentation had simple examples it would be a lot easier and I am new to JUCE and C++ …