summaryrefslogtreecommitdiff
path: root/src/displayapp/screens/Music.cpp
diff options
context:
space:
mode:
authorRiku Isokoski <riksu9000@gmail.com>2022-03-28 17:00:23 +0300
committerRiku Isokoski <riksu9000@gmail.com>2022-04-25 15:51:12 +0300
commit34858d0a6cf750ec53bc160e75fcc29dbeed5e83 (patch)
tree5cb5fcd32909f24d1cb5da50ddb1a1e70be80fbc /src/displayapp/screens/Music.cpp
parentf82aa71eb0dbf4f026a4e7ff0cc848dbf307b98e (diff)
Update track progress in MusicService. Fix #127
Diffstat (limited to 'src/displayapp/screens/Music.cpp')
-rw-r--r--src/displayapp/screens/Music.cpp33
1 files changed, 11 insertions, 22 deletions
diff --git a/src/displayapp/screens/Music.cpp b/src/displayapp/screens/Music.cpp
index 6c91c1e0..b789224b 100644
--- a/src/displayapp/screens/Music.cpp
+++ b/src/displayapp/screens/Music.cpp
@@ -152,32 +152,27 @@ Music::~Music() {
void Music::Refresh() {
if (artist != musicService.getArtist()) {
artist = musicService.getArtist();
- currentLength = 0;
+ currentPosition = 0;
lv_label_set_text(txtArtist, artist.data());
}
if (track != musicService.getTrack()) {
track = musicService.getTrack();
- currentLength = 0;
+ currentPosition = 0;
lv_label_set_text(txtTrack, track.data());
}
if (album != musicService.getAlbum()) {
album = musicService.getAlbum();
- currentLength = 0;
+ currentPosition = 0;
}
if (playing != musicService.isPlaying()) {
playing = musicService.isPlaying();
}
- // Because we increment this ourselves,
- // we can't compare with the old data directly
- // have to update it when there's actually new data
- // just to avoid unnecessary draws that make UI choppy
- if (lastLength != musicService.getProgress()) {
- currentLength = musicService.getProgress();
- lastLength = currentLength;
+ if (currentPosition != musicService.getProgress()) {
+ currentPosition = musicService.getProgress();
UpdateLength();
}
@@ -186,7 +181,7 @@ void Music::Refresh() {
UpdateLength();
}
- if (playing == Pinetime::Controllers::MusicService::MusicStatus::Playing) {
+ if (playing) {
lv_label_set_text_static(txtPlayPause, Symbols::pause);
if (xTaskGetTickCount() - 1024 >= lastIncrement) {
@@ -197,18 +192,12 @@ void Music::Refresh() {
}
frameB = !frameB;
- if (currentLength < totalLength) {
- currentLength +=
- static_cast<int>((static_cast<float>(xTaskGetTickCount() - lastIncrement) / 1024.0f) * musicService.getPlaybackSpeed());
- } else {
+ if (currentPosition >= totalLength) {
// Let's assume the getTrack finished, paused when the timer ends
// and there's no new getTrack being sent to us
- // TODO: ideally this would be configurable
playing = false;
}
lastIncrement = xTaskGetTickCount();
-
- UpdateLength();
}
} else {
lv_label_set_text_static(txtPlayPause, Symbols::play);
@@ -221,15 +210,15 @@ void Music::UpdateLength() {
} else if (totalLength > (99 * 60)) {
lv_label_set_text_fmt(txtTrackDuration,
"%02d:%02d/%02d:%02d",
- (currentLength / (60 * 60)) % 100,
- ((currentLength % (60 * 60)) / 60) % 100,
+ (currentPosition / (60 * 60)) % 100,
+ ((currentPosition % (60 * 60)) / 60) % 100,
(totalLength / (60 * 60)) % 100,
((totalLength % (60 * 60)) / 60) % 100);
} else {
lv_label_set_text_fmt(txtTrackDuration,
"%02d:%02d/%02d:%02d",
- (currentLength / 60) % 100,
- (currentLength % 60) % 100,
+ (currentPosition / 60) % 100,
+ (currentPosition % 60) % 100,
(totalLength / 60) % 100,
(totalLength % 60) % 100);
}