Firelands128 / photo_gallery

A Flutter plugin that retrieves images and videos from mobile native gallery.
BSD 3-Clause "New" or "Revised" License
68 stars 62 forks source link

[bug] Example app is crashing in Android emulator when MediumType is `video` #3

Closed wildsurfer closed 4 years ago

wildsurfer commented 4 years ago

Steps to reproduce:

  1. Shoot any video with camera
  2. Go to line 33 of main.dart file in example folder https://github.com/Firelands128/photo_gallery/blob/master/example/lib/main.dart#L33
  3. Replace MediumType.photo with MediumType.video
  4. Start the app
  5. Click on 'Camera' folder

Instead of seeing a list of video thumbnails app crashes with a message very close to one I described in https://github.com/Firelands128/photo_gallery/issues/2

I was able to debug it a bit in Android Studio and it looks like the problem is here: https://github.com/Firelands128/photo_gallery/blob/181d2ce10d4103415a63b49c5771769a5cf17202/android/src/main/kotlin/com/morbit/photogallery/PhotoGalleryPlugin.kt#L385-L398

mediumType is null when you're trying to list videos and it fails in line 394

Launching lib/main.dart on sdk gphone x86 in debug mode...
Running Gradle task 'assembleDebug'...
✓ Built build/app/outputs/apk/debug/app-debug.apk.
Debug service listening on ws://127.0.0.1:49448/JIka_ZEAtSE=/ws
Syncing files to device sdk gphone x86...
I/Choreographer(16460): Skipped 64 frames!  The application may be doing too much work on its main thread.
E/AndroidRuntime(16460): FATAL EXCEPTION: AsyncTask #1
E/AndroidRuntime(16460): Process: com.morbit.photo_gallery_example, PID: 16460
E/AndroidRuntime(16460): java.lang.RuntimeException: An error occurred while executing doInBackground()
E/AndroidRuntime(16460):    at android.os.AsyncTask$4.done(AsyncTask.java:415)
E/AndroidRuntime(16460):    at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:383)
E/AndroidRuntime(16460):    at java.util.concurrent.FutureTask.setException(FutureTask.java:252)
E/AndroidRuntime(16460):    at java.util.concurrent.FutureTask.run(FutureTask.java:271)
E/AndroidRuntime(16460):    at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:305)
E/AndroidRuntime(16460):    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
E/AndroidRuntime(16460):    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
E/AndroidRuntime(16460):    at java.lang.Thread.run(Thread.java:923)
E/AndroidRuntime(16460): Caused by: java.io.FileNotFoundException: No item at content://media/external/images/media/43
E/AndroidRuntime(16460):    at android.database.DatabaseUtils.readExceptionWithFileNotFoundExceptionFromParcel(DatabaseUtils.java:151)
E/AndroidRuntime(16460):    at android.content.ContentProviderProxy.openTypedAssetFile(ContentProviderNative.java:781)
E/AndroidRuntime(16460):    at android.content.ContentResolver.openTypedAssetFileDescriptor(ContentResolver.java:1983)
E/AndroidRuntime(16460):    at android.content.ContentResolver.openTypedAssetFile(ContentResolver.java:1888)
E/AndroidRuntime(16460):    at android.content.ContentResolver.lambda$loadThumbnail$0(ContentResolver.java:4040)
E/AndroidRuntime(16460):    at android.content.-$$Lambda$ContentResolver$7ILY1SWNxC2xhk-fQUG6tAXW9Ik.call(Unknown Source:10)
E/AndroidRuntime(16460):    at android.graphics.ImageDecoder$CallableSource.createImageDecoder(ImageDecoder.java:558)
E/AndroidRuntime(16460):    at android.graphics.ImageDecoder.decodeBitmapImpl(ImageDecoder.java:1862)
E/AndroidRuntime(16460):    at android.graphics.ImageDecoder.decodeBitmap(ImageDecoder.java:1855)
E/AndroidRuntime(16460):    at android.content.ContentResolver.loadThumbnail(ContentResolver.java:4039)
E/AndroidRuntime(16460):    at android.content.ContentResolver.loadThumbnail(ContentResolver.java:4023)
E/AndroidRuntime(16460):    at com.morbit.photogallery.PhotoGalleryPlugin.getImageThumbnail(PhotoGalleryPlugin.kt:405)
E/AndroidRuntime(16460):    at com.morbit.photogallery.PhotoGalleryPlugin.getThumbnail(PhotoGalleryPlugin.kt:394)
E/AndroidRuntime(16460):    at com.morbit.photogallery.PhotoGalleryPlugin.access$getThumbnail(PhotoGalleryPlugin.kt:22)
E/AndroidRuntime(16460):    at com.morbit.photogallery.PhotoGalleryPlugin$onMethodCall$7.invoke(PhotoGalleryPlugin.kt:118)
E/AndroidRuntime(16460):    at com.morbit.photogallery.PhotoGalleryPlugin$onMethodCall$7.invoke(PhotoGalleryPlugin.kt:22)
E/AndroidRuntime(16460):    at com.morbit.photogallery.BackgroundAsyncTask.doInBackground(PhotoGalleryPlugin.kt:619)
E/AndroidRuntime(16460):    at com.morbit.photogallery.BackgroundAsyncTask.doInBackground(PhotoGalleryPlugin.kt:613)
E/AndroidRuntime(16460):    at android.os.AsyncTask$3.call(AsyncTask.java:394)
E/AndroidRuntime(16460):    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
E/AndroidRuntime(16460):    ... 4 more
I/Process (16460): Sending signal. PID: 16460 SIG: 9
/Users/kuzma/Development/flutter/bin/flutter doctor --verbose
[✓] Flutter (Channel stable, v1.17.5, on Mac OS X 10.15.6 19G73, locale en-GB)
    • Flutter version 1.17.5 at /Users/kuzma/Development/flutter
    • Framework revision 8af6b2f038 (7 weeks ago), 2020-06-30 12:53:55 -0700
    • Engine revision ee76268252
    • Dart version 2.8.4

[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.2)
    • Android SDK at /Users/kuzma/Library/Android/sdk
    • Platform android-30, build-tools 30.0.2
    • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6222593)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 11.6)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 11.6, Build version 11E708
    • CocoaPods version 1.9.3

[✓] Android Studio (version 4.0)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin version 48.1.2
    • Dart plugin version 193.7361
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6222593)

[!] IntelliJ IDEA Ultimate Edition (version 2020.1.4)
    • IntelliJ at /Applications/IntelliJ IDEA.app
    ✗ Flutter plugin not installed; this adds Flutter specific functionality.
    ✗ Dart plugin not installed; this adds Dart specific functionality.
    • For information about installing plugins, see
      https://flutter.dev/intellij-setup/#installing-the-plugins

[✓] VS Code (version 1.48.0)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.13.2

[✓] Connected device (1 available)
    • sdk gphone x86 • emulator-5556 • android-x86 • Android 11 (API 30) (emulator)

! Doctor found issues in 1 category.
Process finished with exit code 0
camilo1498 commented 4 years ago

Hi i am trying this plugin but when i try it in a physical device the application crash on run with this message (i use the same code that was published in pub.dev)

Performing hot reload... Syncing files to device MI 9... Reloaded 3 of 831 libraries in 591ms. I/flutter (28821): 2 I/flutter (28821): 0 E/AndroidRuntime(28821): FATAL EXCEPTION: AsyncTask #1 E/AndroidRuntime(28821): Process: dev.instagram.instagram_clone, PID: 28821 E/AndroidRuntime(28821): java.lang.RuntimeException: An error occurred while executing doInBackground() E/AndroidRuntime(28821): at android.os.AsyncTask$4.done(AsyncTask.java:399) E/AndroidRuntime(28821): at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:383) E/AndroidRuntime(28821): at java.util.concurrent.FutureTask.setException(FutureTask.java:252) E/AndroidRuntime(28821): at java.util.concurrent.FutureTask.run(FutureTask.java:271) E/AndroidRuntime(28821): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:289) E/AndroidRuntime(28821): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167) E/AndroidRuntime(28821): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641) E/AndroidRuntime(28821): at java.lang.Thread.run(Thread.java:919) E/AndroidRuntime(28821): Caused by: java.io.FileNotFoundException: Failed to create image decoder with message 'invalid input'Input contained an error. E/AndroidRuntime(28821): at android.database.DatabaseUtils.readExceptionWithFileNotFoundExceptionFromParcel(DatabaseUtils.java:149) E/AndroidRuntime(28821): at android.content.ContentProviderProxy.openTypedAssetFile(ContentProviderNative.java:705) E/AndroidRuntime(28821): at android.content.ContentResolver.openTypedAssetFileDescriptor(ContentResolver.java:1702) E/AndroidRuntime(28821): at android.content.ContentResolver.openTypedAssetFile(ContentResolver.java:1607) E/AndroidRuntime(28821): at android.content.ContentResolver.lambda$loadThumbnail$0(ContentResolver.java:3617) E/AndroidRuntime(28821): at android.content.-$$Lambda$ContentResolver$7ILY1SWNxC2xhk-fQUG6tAXW9Ik.call(Unknown Source:10) E/AndroidRuntime(28821): at android.graphics.ImageDecoder$CallableSource.createImageDecoder(ImageDecoder.java:550) E/AndroidRuntime(28821): at android.graphics.ImageDecoder.decodeBitmapImpl(ImageDecoder.java:1847) E/AndroidRuntime(28821): at android.graphics.ImageDecoder.decodeBitmap(ImageDecoder.java:1840) E/AndroidRuntime(28821): at android.content.ContentResolver.loadThumbnail(ContentResolver.java:3616) E/AndroidRuntime(28821): at android.content.ContentResolver.loadThumbnail(ContentResolver.java:3600) E/AndroidRuntime(28821): at com.morbit.photogallery.PhotoGalleryPlugin.getImageThumbnail(PhotoGalleryPlugin.kt:404) E/AndroidRuntime(28821): at com.morbit.photogallery.PhotoGalleryPlugin.getAlbumThumbnail(PhotoGalleryPlugin.kt:468) E/AndroidRuntime(28821): at com.morbit.photogallery.PhotoGalleryPlugin.access$getAlbumThumbnail(PhotoGalleryPlugin.kt:22) E/AndroidRuntime(28821): at com.morbit.photogallery.PhotoGalleryPlugin$onMethodCall$9.invoke(PhotoGalleryPlugin.kt:127) E/AndroidRuntime(28821): at com.morbit.photogallery.PhotoGalleryPlugin$onMethodCall$9.invoke(PhotoGalleryPlugin.kt:22) E/AndroidRuntime(28821): at com.morbit.photogallery.BackgroundAsyncTask.doInBackground(PhotoGalleryPlugin.kt:615) E/AndroidRuntime(28821): at com.morbit.photogallery.BackgroundAsyncTask.doInBackground(PhotoGalleryPlugin.kt:609) E/AndroidRuntime(28821): at android.os.AsyncTask$3.call(AsyncTask.java:378) E/AndroidRuntime(28821): at java.util.concurrent.FutureTask.run(FutureTask.java:266) E/AndroidRuntime(28821): ... 4 more I/Process (28821): Sending signal. PID: 28821 SIG: 9 Lost connection to device.

wildsurfer commented 4 years ago

@camilo1498, this looks like another issue. You may try to run example app from this repository and if it’s not working with the same error you may create new issue.

Firelands128 commented 4 years ago

Have fixed this bug in the latest version. Check it here. Hopefully it solve your problem.

wildsurfer commented 4 years ago

Works for me! Thanks!