Skip to content

Commit

Permalink
feat(audio-playing): We now correctly dispose the players and try to …
Browse files Browse the repository at this point in the history
…load the first pitches before playing.
  • Loading branch information
hiocas committed May 10, 2022
1 parent ef839c6 commit c6eb294
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
14 changes: 14 additions & 0 deletions lib/blocs/audio_player/audio_player_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'dart:math';
import 'package:bloc/bloc.dart';
import 'package:dart_vlc/dart_vlc.dart';
import 'package:equatable/equatable.dart';
import 'package:flutter/services.dart';
import 'package:thoery_test/modals/progression.dart';
import 'package:tonic/tonic.dart';

Expand Down Expand Up @@ -79,6 +80,14 @@ class AudioPlayerBloc extends Bloc<AudioPlayerEvent, AudioPlayerState> {
});
}

@override
Future<void> close() {
for (Player player in _players) {
player.dispose();
}
return super.close();
}

void reset(Emitter<AudioPlayerState> emit) {
_playing = false;
_baseControl = true;
Expand All @@ -102,6 +111,11 @@ class AudioPlayerBloc extends Bloc<AudioPlayerEvent, AudioPlayerState> {
_currentMeasures != null && _cM < _currentMeasures!.length;
_cM++) {
Progression<Chord> prog = _currentMeasures![_cM];
// First, load the first pitches.
List<Pitch> _loadedP = _walk(prog[_cC]!);
for (var p in _loadedP) {
await rootBundle.load(pitchFileName(p));
}
for (_cC;
_currentMeasures != null && _cC < _currentMeasures![_cM].length;
_cC++) {
Expand Down
1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ dev_dependencies:
# package. See that file for information about deactivating specific lint
# rules and activating additional ones.
flutter_lints: ^1.0.0
msix: ^3.6.1

# For information on the generic Dart part of this file, see the
# following page: https://dart.dev/tools/pub/pubspec
Expand Down

0 comments on commit c6eb294

Please sign in to comment.