imsamgarg / firebase_cached_image

Cache Manager and Cached ImageProvider for Firebase Cloud Storage Objects.
MIT License
10 stars 17 forks source link

Unexpected behaviour by Source.cacheServer. #16

Closed naveeez10 closed 8 months ago

naveeez10 commented 8 months ago

In our app we encountered an issue where a video stored on Firebase Storage would not play if it wasn't already cached locally. Instead of fetching and playing the video from the server, the app would display a black screen and log a "file not found" exception.

Here are the error logs for reference:

The error logs : E/ExoPlayerImplInternal(12046): at android.os.Looper.loopOnce(Looper.java:201) E/ExoPlayerImplInternal(12046): at android.os.Looper.loop(Looper.java:288) E/ExoPlayerImplInternal(12046): at android.os.HandlerThread.run(HandlerThread.java:67) E/ExoPlayerImplInternal(12046): Caused by: com.google.android.exoplayer2.upstream.FileDataSource$FileDataSourceException: java.io.FileNotFoundException: /data/user/0/jp.smartbooks.kodomamo.parentapp/cache/flutter_cached_image/81361b96-0d8b-5910-a5be-251b14dd9261.mp4: open failed: ENOENT (No such file or directory) E/ExoPlayerImplInternal(12046): at com.google.android.exoplayer2.upstream.FileDataSource.openLocalFile(FileDataSource.java:203) E/ExoPlayerImplInternal(12046): at com.google.android.exoplayer2.upstream.FileDataSource.open(FileDataSource.java:114) E/ExoPlayerImplInternal(12046): at com.google.android.exoplayer2.upstream.DefaultDataSource.open(DefaultDataSource.java:263) E/ExoPlayerImplInternal(12046): at com.google.android.exoplayer2.upstream.StatsDataSource.open(StatsDataSource.java:84) E/ExoPlayerImplInternal(12046): at com.google.android.exoplayer2.source.ProgressiveMediaPeriod$ExtractingLoadable.load(ProgressiveMediaPeriod.java:1005) E/ExoPlayerImplInternal(12046): at com.google.android.exoplayer2.upstream.Loader$LoadTask.run(Loader.java:412) E/ExoPlayerImplInternal(12046): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) E/ExoPlayerImplInternal(12046): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:644) E/ExoPlayerImplInternal(12046): at java.lang.Thread.run(Thread.java:1012) E/ExoPlayerImplInternal(12046): Caused by: java.io.FileNotFoundException: /data/user/0/jp.smartbooks.kodomamo.parentapp/cache/flutter_cached_image/81361b96-0d8b-5910-a5be-251b14dd9261.mp4: open failed: ENOENT (No such file or directory) E/ExoPlayerImplInternal(12046): at libcore.io.IoBridge.open(IoBridge.java:574) E/ExoPlayerImplInternal(12046): at java.io.RandomAccessFile.(RandomAccessFile.java:289) E/ExoPlayerImplInternal(12046): at java.io.RandomAccessFile.(RandomAccessFile.java:152) E/ExoPlayerImplInternal(12046): at com.google.android.exoplayer2.upstream.FileDataSource.openLocalFile(FileDataSource.java:184) E/ExoPlayerImplInternal(12046): ... 8 more E/ExoPlayerImplInternal(12046): Caused by: android.system.ErrnoException: open failed: ENOENT (No such file or directory) E/ExoPlayerImplInternal(12046): at libcore.io.Linux.open(Native Method) E/ExoPlayerImplInternal(12046): at libcore.io.ForwardingOs.open(ForwardingOs.java:563) E/ExoPlayerImplInternal(12046): at libcore.io.BlockGuardOs.open(BlockGuardOs.java:274) E/ExoPlayerImplInternal(12046): at libcore.io.ForwardingOs.open(ForwardingOs.java:563) E/ExoPlayerImplInternal(12046): at android.app.ActivityThread$AndroidOs.open(ActivityThread.java:7756) E/ExoPlayerImplInternal(12046): at libcore.io.IoBridge.open(IoBridge.java:560) E/ExoPlayerImplInternal(12046): ... 11 more

To address this problem, we implemented a manual check to determine whether the video was already cached. If it was not found in the cache, we would explicitly set the source to Source.server. Conversely, if the video was cached, we used Source.cacheServer. This solution successfully resolved the playback issue.

imsamgarg commented 8 months ago

I think that file was somehow deleted from the cache directory. getSingleObject method has the check for this condition, but it's not there in the getSingleFile method. I'll fix the issue soon.

imsamgarg commented 8 months ago

Fixed in #17. Thanks for the issue report.

naveeez10 commented 8 months ago

thanks for the quick fix!