Baseflow / Baseflow/flutter_cache_manager

No exist file after call 'getSingleFile'

オープン
#203 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る
主要言語
Dart
スター
809
フォーク
510
平均マージ
6分
マージ済み PR(30日)
1

説明

## 🐛 Bug Report

I will be downloaded mp3 file from cloud storage.
Then used getSingleFile api and custom cache manager.

```dart
class CustomCacheManager extends BaseCacheManager {
factory CustomCacheManager() => _instance ??= CustomCacheManager._();
CustomCacheManager._()
: super(key,
maxAgeCacheObject: const Duration(days: 30),
maxNrOfCacheObjects: 200);

static const key = 'customCache';

static CustomCacheManager _instance;

@override
Future getFilePath() async {
final directory = await getTemporaryDirectory();
return p.join(directory.path, key);
}
}
```

```dart
final result = [];
final cacheManager = fileStorageRepository.getCacheManager;
for (var voice in voices) {
final file = await cacheManager.getSingleFile(voice.url);
print('${file.path} ${file.existsSync()}'); // file.existsSync() -> false
result.add(file);
}
return result;
```
It correctly get file but sometime file is no exist.
But It succeed if retry for a while.

Is cache setting incorrect or usage getSingleFile api incorrect?

Additional comment, attached error log with audio player in Android.
It occur error when play audio file getting from getSingleFile.

```
E/AudioplayersPlugin(26546): Unexpected error!
E/AudioplayersPlugin(26546): java.lang.RuntimeException: Unable to access resource
E/AudioplayersPlugin(26546): at xyz.luan.audioplayers.WrappedMediaPlayer.setSource(WrappedMediaPlayer.java:289)
E/AudioplayersPlugin(26546): at xyz.luan.audioplayers.WrappedMediaPlayer.setUrl(WrappedMediaPlayer.java:54)
E/AudioplayersPlugin(26546): at xyz.luan.audioplayers.AudioplayersPlugin.handleMethodCall(AudioplayersPlugin.java:65)
E/AudioplayersPlugin(26546): at xyz.luan.audioplayers.AudioplayersPlugin.onMethodCall(AudioplayersPlugin.java:44)
E/AudioplayersPlugin(26546): at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:226)
E/AudioplayersPlugin(26546): at io.flutter.embedding.engine.dart.DartMessenger.handleMessageFromDart(DartMessenger.java:85)
E/AudioplayersPlugin(26546): at io.flutter.embedding.engine.FlutterJNI.handlePlatformMessage(FlutterJNI.java:631)
E/AudioplayersPlugin(26546): at android.os.MessageQueue.nativePollOnce(Native Method)
E/AudioplayersPlugin(26546): at android.os.MessageQueue.next(MessageQueue.java:336)
E/AudioplayersPlugin(26546): at android.os.Looper.loop(Looper.java:174)
E/AudioplayersPlugin(26546): at android.app.ActivityThread.main(ActivityThread.java:7356)
E/AudioplayersPlugin(26546): at java.lang.reflect.Method.invoke(Native Method)
E/AudioplayersPlugin(26546): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
E/AudioplayersPlugin(26546): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
E/AudioplayersPlugin(26546): Caused by: java.io.FileNotFoundException: /data/user/0/com.sample.app/cache/customCache/531acd30-cd4e-11ea-9fe9-5ba2b4995f64.mp3: open failed: ENOENT (No such file or directory)
E/AudioplayersPlugin(26546): at libcore.io.IoBridge.open(IoBridge.java:496)
E/AudioplayersPlugin(26546): at java.io.FileInputStream.(FileInputStream.java:159)
E/AudioplayersPlugin(26546): at android.media.MediaPlayer.setDataSource(MediaPlayer.java:1182)
E/AudioplayersPlugin(26546): at android.media.MediaPlayer.setDataSource(MediaPlayer.java:1160)
E/AudioplayersPlugin(26546): at android.media.MediaPlayer.setDataSource(MediaPlayer.java:1125)
E/AudioplayersPlugin(26546): at xyz.luan.audioplayers.WrappedMediaPlayer.setSource(WrappedMediaPlayer.java:287)
E/AudioplayersPlugin(26546): ... 13 more
E/AudioplayersPlugin(26546): Caused by: android.system.ErrnoException: open failed: ENOENT (No such file or directory)
E/AudioplayersPlugin(26546): at libcore.io.Linux.open(Native Method)
E/AudioplayersPlugin(26546): at libcore.io.ForwardingOs.open(ForwardingOs.java:167)
E/AudioplayersPlugin(26546): at libcore.io.BlockGuardOs.open(BlockGuardOs.java:252)
E/AudioplayersPlugin(26546): at libcore.io.ForwardingOs.open(ForwardingOs.java:167)
E/AudioplayersPlugin(26546): at android.app.ActivityThread$AndroidOs.open(ActivityThread.java:7255)
E/AudioplayersPlugin(26546): at libcore.io.IoBridge.open(IoBridge.java:482)
E/AudioplayersPlugin(26546): ... 18 more
E/MethodChannel#xyz.luan/audioplayers(26546): Failed to handle method call
E/MethodChannel#xyz.luan/audioplayers(26546): java.lang.IllegalArgumentException: Unsupported value: java.lang.RuntimeException: Unable to access resource
E/MethodChannel#xyz.luan/audioplayers(26546): at io.flutter.plugin.common.StandardMessageCodec.writeValue(StandardMessageCodec.java:278)
E/MethodChannel#xyz.luan/audioplayers(26546): at io.flutter.plugin.common.StandardMethodCodec.encodeErrorEnvelope(StandardMethodCodec.java:69)
E/MethodChannel#xyz.luan/audioplayers(26546): at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler$1.error(MethodChannel.java:236)
E/MethodChannel#xyz.luan/audioplayers(26546): at xyz.luan.audioplayers.AudioplayersPlugin.onMethodCall(AudioplayersPlugin.java:47)
E/MethodChannel#xyz.luan/audioplayers(26546): at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:226)
E/MethodChannel#xyz.luan/audioplayers(26546): at io.flutter.embedding.engine.dart.DartMessenger.handleMessageFromDart(DartMessenger.java:85)
E/MethodChannel#xyz.luan/audioplayers(26546): at io.flutter.embedding.engine.FlutterJNI.handlePlatformMessage(FlutterJNI.java:631)
E/MethodChannel#xyz.luan/audioplayers(26546): at android.os.MessageQueue.nativePollOnce(Native Method)
E/MethodChannel#xyz.luan/audioplayers(26546): at android.os.MessageQueue.next(MessageQueue.java:336)
E/MethodChannel#xyz.luan/audioplayers(26546): at android.os.Looper.loop(Looper.java:174)
E/MethodChannel#xyz.luan/audioplayers(26546): at android.app.ActivityThread.main(ActivityThread.java:7356)
E/MethodChannel#xyz.luan/audioplayers(26546): at java.lang.reflect.Method.invoke(Native Method)
E/MethodChannel#xyz.luan/audioplayers(26546): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
E/MethodChannel#xyz.luan/audioplayers(26546): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
```

### Expected behavior
Correctly get files.

### Reproduction steps
none

### Configuration

**Version:** 1.4.1

**Platform:**
- [x] :iphone: iOS
- [x] :robot: Android

コントリビューションガイド

コントリビューションガイドを開く

調査の方向性

Start by examining BaseCacheManager.getSingleFile and the overridden getFilePath in the reported CustomCacheManager, then reproduce the intermittent case on Android using the supplied audio-player failure. Check whether the returned path still exists before playback and compare the cache manager result with the ENOENT path in the log. Done means getSingleFile consistently returns an existing playable file.

索引モデルが issue の本文から書いたものです。

評価

技術スタック
dart, flutter
領域
mobile-dev
issue の種類
バグ
難易度
4/5
見積もり時間
3〜5日
活発さ
停滞
明瞭さ
説明が足りない
初心者へのやさしさ
25/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。