KasemJaffer / media_picker_builder

A Flutter plugin that returns multimedia picker data such as folders and its content path list to build your own custom flutter picker
Apache License 2.0
24 stars 29 forks source link

Bad performances. #3

Open xpader opened 5 years ago

xpader commented 5 years ago

Whatever iOS or Android, when devices has alot of picture, and calling MediaPickerBuilder.getAlbums, It looks like media_picker_builder try to build all of photos or videos thumbnail and get path for it, This is very slow and use too much memory, sometime my app crashed because this, Is there anyway to disable auto generate thumbnail? or let it as a getter or Future or someother defer behavior?

KasemJaffer commented 4 years ago

Hi,

getAlbums actually only returns thumbnails if there was already a thumbnail cached in the device. If not, it will not generate a new thumbnail.

Get the thumbnail using getMediaFile individually when the item is in display.

i.e.

if(mediaFile.thumbnailPath == null)

FutureBuilder(
            future: MediaPickerBuilder.getMediaFile(
              fileId: mediaFile.id,
              type: mediaFile.type,
              loadIOSPath: true,
              loadThumbnail: true,
            ),
            builder: (BuildContext context, AsyncSnapshot<MediaFile> snapshot) {
              if (snapshot.hasData) {
                var updatedMediaFile = snapshot.data;
                mediaFile.thumbnailPath = updatedMediaFile.thumbnailPath;
                mediaFile.duration = updatedMediaFile.duration;
                mediaFile.mimeType = updatedMediaFile.mimeType;
                mediaFile.orientation = updatedMediaFile.orientation;

}

I understand there is a performance issue (ONLY on iOS) when you have a lot of assets (i.e >2k) and its not related to generating the thumbnail. It's how the albums and pictures are stored in iOS and the native api provided by iOS is not scalable for retrieving that many assets.

There is no performance issue with android though. I have over 10k pictures and videos and its very quick.

KasemJaffer commented 4 years ago

I am working on fixing the performance for iOS. Any suggestions or help will be appreciated.

VictorUvarov commented 4 years ago

@KasemJaffer It looks like you can fetch a fixed amount of images on iOS. https://developer.apple.com/documentation/photokit/phfetchoptions/1624761-fetchlimit. Maybe it would be best to only fetch maybe 25 assets at a time and then fetch more when requested.

BradyEdgar94 commented 4 years ago

Did this ever get fixed? I still have bad performance for iOS

Slihao commented 3 years ago

修复了吗?