justsoft / video_thumbnail

This plugin generates thumbnail from video file or URL. It returns image in memory or writes into a file. It offers rich options to control the image format, resolution and quality. Supports iOS and Android.
MIT License
183 stars 238 forks source link

BUG - This media cannot be used #94

Open marcobraghim opened 2 years ago

marcobraghim commented 2 years ago

I don't know why this error is occurring and I don't know how to reproduce it because this error does not happen every time...

OS: iOS

Flutter 2.8.0 • channel stable • https://github.com/flutter/flutter.git Framework • revision cf44000065 (2 weeks ago) • 2021-12-08 14:06:50 -0800 Engine • revision 40a99c5951 Tools • Dart 2.15.0

Flutter Doctor: No issues found!

PlatformException(IO Error, Failed to write data to file, null, null)
couldn't generate thumbnail, error:Error Domain=AVFoundationErrorDomain Code=-11832 "Cannot Open" UserInfo={NSLocalizedFailureReason=This media cannot be used., NSLocalizedDescription=Cannot Open, NSUnderlyingError=0x2821eeeb0 {Error Domain=NSOSStatusErrorDomain Code=-12431 "(null)"}}
APPXOTICA commented 2 years ago

I encountered the same issue when I was trying to get a thumbnail from a video taken by camera. This seems to happen on iOS only. Here's a workaround.

  1. Install two packages : image_gallery_saver, photo_manager
  2. Save video file taken by camera into user gallery
  3. Find the saved video with photo_manager like code below.
  Future<AssetEntity?> fetchLatestVideoAsset() async {
    final albums = await PhotoManager.getAssetPathList(
        onlyAll: true,
        type: RequestType.video,
    );
    if (albums.isEmpty) return null;
    final assets = await albums.first.getAssetListPaged(0, 1);
    return assets.first;
  }
marcobraghim commented 2 years ago

fetchLatestVideoAsset

Thanks for the answer and this workaround. Anyway, we need this issue to be fixed...

mjbader commented 2 years ago

I have a fix, though I am not sure it's the proper fix. I found that if you set the requestedTimeToleranceAfter to 100ms, then the thumbnail is properly generated. I forked the repo and made a change myself for a personal project here:

https://github.com/mjbader/video_thumbnail/commit/5971ca77cd8b588f8806b99bf80916327e8551fa

FilledStacks commented 2 years ago

I'm gonna try and use this fix now. @mjbader are you still using your fork successfully ?

justsoft commented 2 years ago

@mjbader Thank you for sharing this fix.

theappideasankit commented 1 year ago
Screenshot 2023-01-14 at 12 19 22 AM