Skip to content

Commit

Permalink
fix: set _isPaused to false when set to inactive state, and only pi…
Browse files Browse the repository at this point in the history
…ck songs near the top of the list.
  • Loading branch information
darylhjd committed Oct 28, 2021
1 parent e9dec86 commit 6d54317
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions lib/models/spotify_controller_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ class SpotifyControllerModel with ChangeNotifier {
// For ensuring connection to Spotify app.
late Stream<ConnectionStatus> _connectionStream;

// Used by the SpotifyControllerModel to search for songs.
final CadencePedometerModel _cadenceModel = CadencePedometerModel();

// Player status.
Timer? _playerStateUpdater;
PlayerState? _lastState;
Expand All @@ -51,9 +54,6 @@ class SpotifyControllerModel with ChangeNotifier {
bool _hasStartedFind = false; // Flag to check if app already finding new song
bool _isPaused = false; // Flag to check if player paused song while finding.

// Used by the SpotifyControllerModel to search for songs.
final CadencePedometerModel _cadenceModel = CadencePedometerModel();

// Cadence data
String _cadenceValue = "-";
String _cadenceStatus = "Inactive";
Expand Down Expand Up @@ -216,7 +216,7 @@ class SpotifyControllerModel with ChangeNotifier {
return;
}
// Select a random song from the list.
selectedSong = songs[_random.nextInt(songs.length)];
selectedSong = songs[_random.nextInt((songs.length / 4).ceil())];
// Once we select this song, then we find the Spotify URI for this song.
uri = await _getTrackSpotifyURI(selectedSong);
if (!_isActive) {
Expand Down Expand Up @@ -274,7 +274,7 @@ class SpotifyControllerModel with ChangeNotifier {
// _setInactiveState : Sets the model to inactive state.
// This will also stop the playerStateUpdater and cancels any upcoming searches.
void _setInactiveState() {
_isActive = _hasStartedFind = false;
_isActive = _hasStartedFind = _isPaused = false;
// Stop the player state checker.
_playerStateUpdater?.cancel();
// Reset last PlayerState
Expand Down

0 comments on commit 6d54317

Please sign in to comment.