1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-10 23:44:24 +00:00

Android: Allow recording demo to write files on recent Android versions

This commit is contained in:
reuk 2023-01-18 18:47:04 +00:00
parent 070a6b35e9
commit 273275cf07
No known key found for this signature in database
GPG key ID: 9ADCD339CFC98A11
3 changed files with 35 additions and 33 deletions

View file

@ -244,10 +244,8 @@ struct SlowerBouncingNumber : public BouncingNumber
inline std::unique_ptr<InputSource> makeInputSource (const URL& url)
{
#if JUCE_ANDROID
if (auto doc = AndroidDocument::fromDocument (url))
if (const auto doc = AndroidDocument::fromDocument (url))
return std::make_unique<AndroidDocumentInputSource> (doc);
#endif
#if ! JUCE_IOS
if (url.isLocalFile())
@ -257,4 +255,17 @@ inline std::unique_ptr<InputSource> makeInputSource (const URL& url)
return std::make_unique<URLInputSource> (url);
}
inline std::unique_ptr<OutputStream> makeOutputStream (const URL& url)
{
if (const auto doc = AndroidDocument::fromDocument (url))
return doc.createOutputStream();
#if ! JUCE_IOS
if (url.isLocalFile())
return url.getLocalFile().createOutputStream();
#endif
return url.createOutputStream();
}
#endif // PIP_DEMO_UTILITIES_INCLUDED

View file

@ -305,17 +305,14 @@ private:
LiveScrollingAudioDisplay liveAudioScroller;
RecordingThumbnail recordingThumbnail;
AudioRecorder recorder { recordingThumbnail.getAudioThumbnail() };
AudioRecorder recorder { recordingThumbnail.getAudioThumbnail() };
Label explanationLabel { {}, "This page demonstrates how to record a wave file from the live audio input..\n\n"
#if (JUCE_ANDROID || JUCE_IOS)
"After you are done with your recording you can share with other apps."
#else
"Pressing record will start recording a file in your \"Documents\" folder."
#endif
};
Label explanationLabel { {},
"This page demonstrates how to record a wave file from the live audio input.\n\n"
"After you are done with your recording you can choose where to save it." };
TextButton recordButton { "Record" };
File lastRecording;
FileChooser chooser { "Output file...", File::getCurrentWorkingDirectory().getChildFile ("recording.wav"), "*.wav" };
void startRecording()
{
@ -350,28 +347,18 @@ private:
{
recorder.stop();
#if JUCE_CONTENT_SHARING
SafePointer<AudioRecordingDemo> safeThis (this);
File fileToShare = lastRecording;
chooser.launchAsync ( FileBrowserComponent::saveMode
| FileBrowserComponent::canSelectFiles
| FileBrowserComponent::warnAboutOverwriting,
[this] (const FileChooser& c)
{
if (FileInputStream inputStream (lastRecording); inputStream.openedOk())
if (const auto outputStream = makeOutputStream (c.getURLResult()))
outputStream->writeFromInputStream (inputStream, -1);
ContentSharer::getInstance()->shareFiles (Array<URL> ({URL (fileToShare)}),
[safeThis, fileToShare] (bool success, const String& error)
{
if (fileToShare.existsAsFile())
fileToShare.deleteFile();
if (! success && error.isNotEmpty())
NativeMessageBox::showAsync (MessageBoxOptions()
.withIconType (MessageBoxIconType::WarningIcon)
.withTitle ("Sharing Error")
.withMessage (error),
nullptr);
});
#endif
lastRecording = File();
recordButton.setButtonText ("Record");
recordingThumbnail.setDisplayFullThumbnail (true);
recordButton.setButtonText ("Record");
recordingThumbnail.setDisplayFullThumbnail (true);
});
}
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (AudioRecordingDemo)

View file

@ -43,7 +43,11 @@ static StringArray jucePermissionToAndroidPermissions (RuntimePermissions::Permi
"android.permission.BLUETOOTH_CONNECT" };
}
case RuntimePermissions::writeExternalStorage: return { "android.permission.WRITE_EXTERNAL_STORAGE" };
// WRITE_EXTERNAL_STORAGE has no effect on SDK 29+
case RuntimePermissions::writeExternalStorage:
return getAndroidSDKVersion() < 29 ? StringArray { "android.permission.WRITE_EXTERNAL_STORAGE" }
: StringArray{};
case RuntimePermissions::camera: return { "android.permission.CAMERA" };
case RuntimePermissions::readExternalStorage: