Baseflow / Baseflow/flutter_cache_manager

No exist file after call 'getSingleFile'

Ouverte
#203 0 commentaires 0 réactions 0 personnes assignées Voir sur GitHub
Langage dominant
Dart
Étoiles
809
Forks
510
Merge moyen
6 min
PR mergées (30 j)
1

Description

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

Guide de contribution

Ouvrir le guide de contribution

Piste de recherche

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.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Évaluation

Stack technique
dart, flutter
Domaine
mobile-dev
Type d'issue
Bug
Difficulté
4/5
Temps estimé
3-5 jours
Activité
À l'abandon
Clarté
À clarifier
Accessibilité débutants
25/100

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.