1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-09 23:34:20 +00:00

ConvolutionDemo: Fix bug where "Load File..." button only worked once

This commit is contained in:
reuk 2020-12-14 18:29:40 +00:00
parent cd41e31cb5
commit d31b85ef00
No known key found for this signature in database
GPG key ID: 9ADCD339CFC98A11

View file

@ -587,37 +587,42 @@ private:
{
audioFileReader.stop();
if (fileChooser == nullptr)
if (fileChooser != nullptr)
return;
SafePointer<AudioPlayerHeader> safeThis (this);
if (! RuntimePermissions::isGranted (RuntimePermissions::readExternalStorage))
{
SafePointer<AudioPlayerHeader> safeThis (this);
if (! RuntimePermissions::isGranted (RuntimePermissions::readExternalStorage))
{
RuntimePermissions::request (RuntimePermissions::readExternalStorage,
[safeThis] (bool granted) mutable
{
if (granted)
safeThis->openFile();
});
return;
}
fileChooser.reset (new FileChooser ("Select an audio file...", File(), "*.wav;*.mp3;*.aif"));
fileChooser->launchAsync (FileBrowserComponent::openMode | FileBrowserComponent::canSelectFiles,
[safeThis] (const FileChooser& fc) mutable
{
if (safeThis != nullptr && fc.getURLResults().size() > 0)
{
auto u = fc.getURLResult();
if (! safeThis->audioFileReader.loadURL (u))
NativeMessageBox::showOkCancelBox (AlertWindow::WarningIcon, "Error loading file", "Unable to load audio file", nullptr, nullptr);
else
safeThis->thumbnailComp.setCurrentURL (u);
}
}, nullptr);
RuntimePermissions::request (RuntimePermissions::readExternalStorage,
[safeThis] (bool granted) mutable
{
if (granted)
safeThis->openFile();
});
return;
}
fileChooser.reset (new FileChooser ("Select an audio file...", File(), "*.wav;*.mp3;*.aif"));
fileChooser->launchAsync (FileBrowserComponent::openMode | FileBrowserComponent::canSelectFiles,
[safeThis] (const FileChooser& fc) mutable
{
if (safeThis == nullptr)
return;
if (fc.getURLResults().size() > 0)
{
auto u = fc.getURLResult();
if (! safeThis->audioFileReader.loadURL (u))
NativeMessageBox::showOkCancelBox (AlertWindow::WarningIcon, "Error loading file", "Unable to load audio file", nullptr, nullptr);
else
safeThis->thumbnailComp.setCurrentURL (u);
}
safeThis->fileChooser = nullptr;
}, nullptr);
}
void changeListenerCallback (ChangeBroadcaster*) override