media_picker_builder icon indicating copy to clipboard operation
media_picker_builder copied to clipboard

Bad performances.

Open xpader opened this issue 5 years ago • 5 comments

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?

xpader avatar Aug 29 '19 03:08 xpader

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 avatar Sep 24 '19 21:09 KasemJaffer

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

KasemJaffer avatar Sep 24 '19 21:09 KasemJaffer

@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.

VictorUvarov avatar Jun 16 '20 04:06 VictorUvarov

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

BradyEdgar94 avatar Jul 27 '20 02:07 BradyEdgar94

修复了吗?

Slihao avatar Sep 30 '20 03:09 Slihao