Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
2 tasks done
Horschig opened this issue Nov 4, 2023 · 1 comment · May be fixed by #1790
Open
2 tasks done

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

Horschig opened this issue Nov 4, 2023 · 1 comment · May be fixed by #1790
Assignees

Comments

@Horschig
Copy link

Horschig commented Nov 4, 2023

Checklist

  • I read the troubleshooting guide before raising this issue
  • 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

  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

    ...
    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:

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

@Horschig Horschig added the bug label Nov 4, 2023
@Gustl22
Copy link
Collaborator

Gustl22 commented Nov 7, 2023

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.

@Gustl22 Gustl22 added platform-windows Affects the windows platform feature-request and removed bug labels Nov 20, 2023
@Gustl22 Gustl22 changed the title File handle is inaccessible after calling release() File handle is inaccessible after calling release() / Implement ReleaseMode.release Nov 20, 2023
@Gustl22 Gustl22 self-assigned this Mar 15, 2024
@Gustl22 Gustl22 linked a pull request Apr 12, 2024 that will close this issue
7 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants