fix(android): Prevent out of memory errors on Android when selecting large media (video) files from the gallery picker. #923
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Platforms affected
Android
Motivation and Context
Changes from #906 resulted in all gallery picker results being read in full into a byte array.
See this line.
Reading in the data fully into memory works generally fine when dealing with images.
When handling larger files (videos for example), it will nearly always result in an out of memory error (reading too much data in one go).
With videos no transformation is required, the URI simply need to be returned.
Steps to recreate issue:
camera.getPicture
withdestinationType
asCamera.DestinationType.FILE_URI
mediaType
asCamera.MediaType .VIDEO
sourceType
asCamera.PictureSourceType.PHOTOLIBRARY
Description
Re-ordered and cleaned up the code for
processResultFromGallery
to only read the file data when required.If its a video or MIME type which it cannot transform, then simply return the URI.
Similarly if the special case for just returning the path without scaling is met, avoid reading in any data.
Testing
No issues spotted. Images and videos were selected and saved into application storage without issue.
Checklist
(platform)
if this change only applies to one platform (e.g.(android)
)