Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions packages/audioplayers/lib/src/audio_cache.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class AudioCache {
/// On mobile/desktop, the URIs are from local files where the bytes have been
/// copied.
/// On web, the URIs are external links for pre-loaded files.
Map<String, Uri> loadedFiles = {};
final Map<String, Uri> loadedFiles = {};

/// This is the path inside your assets folder where your files lie.
///
Expand All @@ -50,7 +50,7 @@ class AudioCache {
/// Does nothing if the file was not on cache.
/// Note: web relies on the browser cache which is handled entirely by the
/// browser, thus this will no-op.
Future<void> clear(Uri fileName) async {
Future<void> clear(String fileName) async {
final uri = loadedFiles.remove(fileName);
if (uri != null && !kIsWeb) {
await File(uri.toFilePath()).delete();
Expand All @@ -59,7 +59,7 @@ class AudioCache {

/// Clears the whole cache.
Future<void> clearAll() async {
await Future.wait(loadedFiles.values.map(clear));
await Future.wait(loadedFiles.keys.map(clear));
}

Future<Uri> fetchToMemory(String fileName) async {
Expand Down
Binary file removed packages/audioplayers/test/assets/audio.mp3
Binary file not shown.
12 changes: 12 additions & 0 deletions packages/audioplayers/test/audio_cache_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,17 @@ void main() {
await player.load('audio.mp3');
expect(player.called, hasLength(0));
});

test('clear cache', () async {
final player = MyAudioCache();
await player.load('audio.mp3');
expect(player.loadedFiles['audio.mp3'], isNotNull);
player.clearAll();
expect(player.loadedFiles, <String, Uri>{});
await player.load('audio.mp3');
expect(player.loadedFiles.isNotEmpty, isTrue);
player.clear('audio.mp3');
expect(player.loadedFiles, <String, Uri>{});
});
});
}