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
1.99k stars 844 forks source link

File handle is inaccessible after calling release() / Implement ReleaseMode.release #1689

Open Horschig opened 11 months ago

Horschig commented 11 months ago

Checklist

Current bug behaviour

When having played an audio file with releasemode release, the file handle is inaccessible e.g. for overwriting the file.

Expected behaviour

Releasing should properly release the file handle, allowing all file access including overwriting the played file.

Steps to reproduce

  1. Execute flutter run on the code audiotestappx.zip
  2. Click on the + button to have the sound file generated in the temporary folder and played.
  3. Wait until sound has played (~4 seconds)
  4. Click on the + button to have the sound file overwritten in the temporary folder. The newly generated file should be played properly.

Code sample

Code sample In main.dart, call ```dart ... await MyWaveBuilder.exampleAppend(); final Directory tempDir = await getTemporaryDirectory(); final String tempFile = '${tempDir.absolute.path}/out.wav'; MyAudioPlayer.play(tempFile); ``` MyWaveBuilder: ```dart import 'dart:io'; import 'dart:math'; import 'package:wave_builder/wave_builder.dart'; import 'package:path_provider/path_provider.dart'; class MyWaveBuilder { /// Create 1 bar of a 4 random beats static Future exampleAppend() async { var rng = Random(); final Directory tempDir = await getTemporaryDirectory(); final String tempFile = '${tempDir.absolute.path}/out.wav'; var fileOut = File(tempFile); var primary = File('./assets/sounds/primary.wav'); var secondary = File('./assets/sounds/secondary.wav'); var silenceType = WaveBuilderSilenceType.BeginningOfLastSample; var primaryBytes = await primary.readAsBytes(); var secondaryBytes = await secondary.readAsBytes(); await fileOut.create(); var waveBuilder = WaveBuilder(); waveBuilder.appendFileContents(primaryBytes); waveBuilder.appendSilence(750 - rng.nextInt(500), silenceType); waveBuilder.appendFileContents(secondaryBytes); waveBuilder.appendSilence(750 - rng.nextInt(500), silenceType); waveBuilder.appendFileContents(secondaryBytes); waveBuilder.appendSilence(750 - rng.nextInt(500), silenceType); waveBuilder.appendFileContents(secondaryBytes); waveBuilder.appendSilence(750 - rng.nextInt(500), silenceType); await fileOut.writeAsBytes(waveBuilder.fileBytes); } } ``` MyAudioPlayer: ```dart import 'dart:io'; import 'package:audioplayers/audioplayers.dart'; class MyAudioPlayer { static play(String src) async { final player = AudioPlayer(); player.setReleaseMode(ReleaseMode.release); await player.play(DeviceFileSource(src)); } } ```

Affected platforms

Windows

Platform details

Windows 11 (10.0.22621)

AudioPlayers Version

^1.1.1

Build mode

debug

Audio Files/URLs/Sources

See here for zipped assets: soundfiles.zip

Cannot upload raw wav files btw:

image

Screenshots

(sorry for the potato language):

image

Logs

my relevant logs
Full Logs ``` my full logs or a link to a gist ``` Flutter doctor: ``` Output of: flutter doctor -v ```

Related issues / more information

Rebo on Discord thoughtto have solved it with: https://github.com/bluefireteam/audioplayers/pull/1517/files#diff-9bd303c19c9f1e11702b5b6541381f0910cca3c459576aa8a215b0c880a0ab79R342

Working on PR

no way

Gustl22 commented 11 months ago

Note that we haven't implemented the ReleasMode.release properly, see the parity table. Calling release on the player manually may should work.

This should be easy to implement though.