Baseflow / Baseflow/flutter_cache_manager

No exist file after call 'getSingleFile'

Offen
#203 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
Vorherrschende Sprache
Dart
Sterne
809
Forks
510
Ø Merge
6 Min.
Gemergte PRs (30 T.)
1

Beschreibung

## 🐛 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

Beitragsleitfaden

Beitragsleitfaden öffnen

Rechercherichtung

Beginne mit der Untersuchung von BaseCacheManager.getSingleFile und dem überschriebenen getFilePath im gemeldeten CustomCacheManager und reproduziere anschließend den sporadisch auftretenden Fall auf Android mithilfe des bereitgestellten audio-player-Fehlers. Prüfe, ob der zurückgegebene Pfad vor der Wiedergabe noch existiert, und vergleiche das Ergebnis des Cache-Managers mit dem ENOENT-Pfad im Log. Als erledigt gilt die Aufgabe, wenn getSingleFile zuverlässig eine vorhandene, abspielbare Datei zurückgibt.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
dart, flutter
Bereich
mobile-dev
Issue-Typ
Bug
Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Aktivitätsstatus
Veraltet
Klarheit
Muss geklärt werden
Anfängerfreundlichkeit
25/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.