Unloading audio files from readersource / transportsource

I have a simple audio player that loads files with a waveform display.

Is there a way to somehow unload or revert the audio reader source to its blank starting state? I’d like a user to be able to clear the song from the the transport so they can’t play it and also clear the audio thumb with a “clear” button.

In the audio tutorial for playing files they have the code as follows to load the file, but you can’t set a readersource to nullptr or it will crash out.

    void openButtonClicked()
        chooser = std::make_unique<juce::FileChooser> ("Select a Wave file to play...",
                                                       "*.wav");                     // [7]
        auto chooserFlags = juce::FileBrowserComponent::openMode
                          | juce::FileBrowserComponent::canSelectFiles;
        chooser->launchAsync (chooserFlags, [this] (const FileChooser& fc)           // [8]
            auto file = fc.getResult();
            if (file != File{})                                                      // [9]
                auto* reader = formatManager.createReaderFor (file);                 // [10]
                if (reader != nullptr)
                    auto newSource = std::make_unique<juce::AudioFormatReaderSource> (reader, true);   // [11]
                    transportSource.setSource (newSource.get(), 0, nullptr, reader->sampleRate);       // [12]
                    playButton.setEnabled (true);                                                      // [13]
                    readerSource.reset (newSource.release());                                          // [14]

Just to answer my own question, this can be solved by something like this:

    transportSource.setSource(nullptr, 0, nullptr, 0);

and clearing the audiothumb. Duh. I had another problem with a radio button that was causing a problem for this not to work. :slight_smile: