bluefireteam / audioplayers

A Flutter package to play multiple audio files simultaneously (Android/iOS/web/Linux/Windows/macOS)
https://pub.dartlang.org/packages/audioplayers
MIT License
2.01k stars 845 forks source link

[AudioCache] `clear()` error on Windows app #1836

Open JankLai opened 2 months ago

JankLai commented 2 months ago

Checklist

Current bug behaviour

What happened?

I am creating a game on Windows. I am using flame_audio: ^2.10.2 (which depends on audioplayers-6.0.0) for sounds, there is an issue when clearing cache: The audio cache cannot be deleted(Windows only, Android is ok).

From the error log I can see why the file cannot be found is that the file path is wrong, for windows uses backslashes () as directory separators.

Expected behaviour

Be able to delete audio cache for Windows app.

Steps to reproduce

Execute flutter run on the code sample for a Windows App calling AudioCache.clear

Code sample

await FlameAudio.audioCache.load(songName!); // This is ok.
...
FutureOr<void> ClearMusic() async {
  if (songName == null) {
    return;
  }
  if (!useAudioPlayer) {
    await FlameAudio.bgm.stop();
  } else {
    await musicPlayer!.stop();
  }
  await FlameAudio.audioCache.clear(songName!); // Error log.
}

Affected platforms

Windows

Platform details

Windows 11

AudioPlayers Version

6.0.0

Build mode

debug, release

Audio Files/URLs/Sources

No response

Screenshots

No response

Logs

[ERROR:flutter/runtime/dart_vm_initializer.cc(40)] Unhandled Exception: FileSystemException: Cannot delete file, path = '/C:/Users/74218/AppData/Local/Temp/01c990ea-fe02-458e-9226-e4d9f83ce84f/melody/my_music.mp3`

Related issues / more information

No response

Working on PR

no way