audioplayers
audioplayers copied to clipboard
File handle is inaccessible after calling release() / Implement ReleaseMode.release
Checklist
- [X] I read the troubleshooting guide before raising this issue
- [X] I made sure that the issue I am raising doesn't already exist
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
- Execute
flutter run
on the code audiotestappx.zip - Click on the + button to have the sound file generated in the temporary folder and played.
- Wait until sound has played (~4 seconds)
- 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
...
await MyWaveBuilder.exampleAppend();
final Directory tempDir = await getTemporaryDirectory();
final String tempFile = '${tempDir.absolute.path}/out.wav';
MyAudioPlayer.play(tempFile);
MyWaveBuilder:
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<void> 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:
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:
Screenshots
(sorry for the potato language):
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
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.