initialiseAudio method

Future<void> initialiseAudio(
  1. File file
)

Set up audio for new file.

Implementation

Future<void> initialiseAudio(File file) async {
  await _audioPlayer.setFilePath(file.path);
  await _audioPlayer.pause();
  _positionNotifier.value = _audioPlayer.position;
  _durationNotifier.value = _audioPlayer.duration ?? Duration.zero;

  if (!_initialised) {
    _audioPlayer.durationStream.listen((duration) {
      _durationNotifier.value = duration;
    });
    _audioPlayer.positionStream.listen((position) {
      _positionNotifier.value = position;
    });
    _audioPlayer.playerStateStream.listen((playerState) {
      _playerStateNotifier.value = playerState;
    });
    _initialised = true;
  }
}