Skip to content

Commit

Permalink
More fixes to state handling.
Browse files Browse the repository at this point in the history
  • Loading branch information
Kern, Thomas committed Jan 3, 2024
1 parent f456b1a commit 724851c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
30 changes: 22 additions & 8 deletions lib/pages/tracklist/playing_progress.dart
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class _PlayingProgressIndicatorState extends State<PlayingProgressIndicator> wit
late int bitrate;
late Duration duration;
late AnimationController controller;
String? previousPlaybackState;

@override
void initState() {
Expand Down Expand Up @@ -131,20 +132,33 @@ class _PlayingProgressIndicatorState extends State<PlayingProgressIndicator> wit
Expanded(
child: Slider(
value: calculateValue(),
onChangeStart: (double value) async {
try {
previousPlaybackState = await mopidyService.getPlaybackState();
} catch (e) {
Globals.logger.e(e);
}
},
onChanged: (double value) {
if (widget.playbackState != PlaybackState.stopped) {
if (previousPlaybackState != PlaybackState.stopped) {
controller.value = value;
}
},
onChangeEnd: (double value) async {
try {
var pos = (duration.inMilliseconds * value).toInt();
bool success = await mopidyService.seek(pos);
if (success) {
setState(() {
controller.value = value;
timePosition = pos;
});
if (previousPlaybackState != PlaybackState.stopped) {
var pos = (duration.inMilliseconds * value).toInt();
bool success = await mopidyService.seek(pos);
if (success) {
setState(() {
controller.value = value;
timePosition = pos;
});
}
// needs restart because 'seek' stops player.
if (previousPlaybackState == PlaybackState.playing) {
await mopidyService.playback(PlaybackAction.resume, null);
}
}
} catch (e) {
Globals.logger.e(e);
Expand Down
2 changes: 2 additions & 0 deletions lib/pages/tracklist/tracklist_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ class _TrackListState extends State<TrackListPage> {
updatePlayback();
updateSplitMode();

/*
SystemChannels.lifecycle.setMessageHandler((msg) {
// When the app was resumed, update
// tracklist state.
Expand All @@ -212,6 +213,7 @@ class _TrackListState extends State<TrackListPage> {
}
return Future.value(null);
});
*/
}

@override
Expand Down

0 comments on commit 724851c

Please sign in to comment.