2

Hi I'am buiding a game and I loaded the required .wav files to be played when the player colloid with an obstacle :

  FlameAudio.play("file.wav")

But when I restart the app in debug mode it gives me an error:

OS Error: 
FileSystemException (FileSystemException: Cannot open file, path = 'C:\Users\ashoukry\AppData\Local\Temp/file.wav'
"The process cannot access the file because it is being used by another process " 

What I am tried : I used the following code but with no success and it gives the same error:

      AudioPLayer player = await FlameAudio.play("file.wav");

      player.dispose()

Also :

      AudioPLayer player = await FlameAudio.play("file.wav");

      player.release()
aym1781969
  • 545
  • 1
  • 4
  • 16

2 Answers2

1

Hot reload is currently not supported in AudioPlayers, see: https://github.com/bluefireteam/audioplayers/issues/1424 and https://github.com/bluefireteam/audioplayers/issues/1120

It will be quite hard to build support for currently since Flutter isn't calling dispose when doing a hot reload.

spydon
  • 9,372
  • 6
  • 33
  • 63
  • Thanks for your response @spydon but also when I make fully restart (Ctrl +Shift + F5) it gives me the same error not only hot reload – aym1781969 Apr 28 '23 at 06:50
1

I figured out the problem just update the method load in audio_cache.dart:

Future<Uri> load(String fileName) async {
    if (!loadedFiles.containsKey(fileName)) {
      //==========add these lines,it ensures that file is deleted before used again======
       final file = fileSystem.file('${await getTempDir()}/$fileName');
      if (file != null) {
        if (file.existsSync()) await file.delete();
      }
      //=================================
      loadedFiles[fileName] = await fetchToMemory(fileName);
    }
    return loadedFiles[fileName]!;
  }
aym1781969
  • 545
  • 1
  • 4
  • 16