summaryrefslogtreecommitdiff
path: root/src/components/ble/MusicService.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/components/ble/MusicService.cpp
parentf82aa71eb0dbf4f026a4e7ff0cc848dbf307b98e (diff)
Update track progress in MusicService. Fix #127
Diffstat (limited to 'src/components/ble/MusicService.cpp')
-rw-r--r--src/components/ble/MusicService.cpp13
1 files changed, 12 insertions, 1 deletions
diff --git a/src/components/ble/MusicService.cpp b/src/components/ble/MusicService.cpp
index c99aa1e3..83b26a78 100644
--- a/src/components/ble/MusicService.cpp
+++ b/src/components/ble/MusicService.cpp
@@ -152,12 +152,20 @@ int Pinetime::Controllers::MusicService::OnCommand(uint16_t conn_handle, uint16_
albumName = s;
} else if (ble_uuid_cmp(ctxt->chr->uuid, &msStatusCharUuid.u) == 0) {
playing = s[0];
+ // These variables need to be updated, because the progress may not be updated immediately,
+ // leading to getProgress() returning an incorrect position.
+ if (playing) {
+ trackProgressUpdateTime = xTaskGetTickCount();
+ } else {
+ trackProgress += static_cast<int>((static_cast<float>(xTaskGetTickCount() - trackProgressUpdateTime) / 1024.0f) * getPlaybackSpeed());
+ }
} else if (ble_uuid_cmp(ctxt->chr->uuid, &msRepeatCharUuid.u) == 0) {
repeat = s[0];
} else if (ble_uuid_cmp(ctxt->chr->uuid, &msShuffleCharUuid.u) == 0) {
shuffle = s[0];
} else if (ble_uuid_cmp(ctxt->chr->uuid, &msPositionCharUuid.u) == 0) {
trackProgress = (s[0] << 24) | (s[1] << 16) | (s[2] << 8) | s[3];
+ trackProgressUpdateTime = xTaskGetTickCount();
} else if (ble_uuid_cmp(ctxt->chr->uuid, &msTotalLengthCharUuid.u) == 0) {
trackLength = (s[0] << 24) | (s[1] << 16) | (s[2] << 8) | s[3];
} else if (ble_uuid_cmp(ctxt->chr->uuid, &msTrackNumberCharUuid.u) == 0) {
@@ -191,7 +199,10 @@ float Pinetime::Controllers::MusicService::getPlaybackSpeed() const {
return playbackSpeed;
}
-int Pinetime::Controllers::MusicService::getProgress() const {
+int Pinetime::Controllers::MusicService::getProgress() {
+ if (isPlaying()) {
+ return trackProgress + static_cast<int>((static_cast<float>(xTaskGetTickCount() - trackProgressUpdateTime) / 1024.0f) * getPlaybackSpeed());
+ }
return trackProgress;
}