Audio File Player

Hi all,

I’m trying to create an audio plugin that has a button that when clicked, automatically plays a file from a location in my computer, and I’m getting stuck on creating the function that actually plays the file, any help would be great, I’m new to JUCE but trying to learn! Thanks.

Hi geno3658,

Have you followed the tutorial Build an audio player ?

I have, but I’m having trouble implementing how they use it for a GUI plugin into an audio plugin.

In the tutorial the audio is processed like so…

    void getNextAudioBlock (const juce::AudioSourceChannelInfo& bufferToFill) override
    {
        if (readerSource.get() == nullptr)
        {
            bufferToFill.clearActiveBufferRegion();
            return;
        }
 
        transportSource.getNextAudioBlock (bufferToFill);
    }

You can do the exact same thing in a plug-in, the only difference being that you’ll need to create the AudioSourceChannelInfo object yourself, which you can do very simply like so:

void processBlock (AudioBuffer<float>& buffer, MidiBuffer &midiMessages)
{
    juce::AudioSourceChannelInfo channelInfo (buffer);
}

I get that but what I’m getting stuck on is creating the function for the onButtonClick, where it should automatically play a random audio file from my computer.