LeoKlaus / plappa

An Audiobook client for Jellyfin and AudioBookShelf, written in Swift/SwiftUI.
https://plappa.me
160 stars 0 forks source link

[BUG] ABS Progress not correctly tracked across devices #3

Closed Primax12 closed 4 months ago

Primax12 commented 4 months ago

Describe the bug It seems like the app pushes its progress to ABS without checking if it has been the latest device to play the book.

To Reproduce Requires 2 devices connected to an ABS library, both devices having listened to the same book at least once.

  1. Kill Plappa on both device.
  2. Open Plappa on device A and start listening to a book.
  3. Pause progress and kill the app on device A.
  4. Check in ABS, the progress has been updated.
  5. Open Plappa on device B and start listening on book played previously.
  6. The app resumes where the device B left off, and pushes this progress to ABS, loosing all the progress from device A.

Expected behavior The app detects that the device B isn't in sync with ABS, and moves its book progress to ABS latest progress.

Additional notes / Suggestions May be compare the timestamp of the most recent session played on the device with the timestamp of the latest session in ABS? (If ABS provides such data in its API)

Comparing timestamp and not progress in the book could allow to move backward on device A and resume at that place in device B.

This check could be done every time the play button is pressed, allowing to resume progress across devices without killing the app (as long as the ABS backend is reachable).

PS: Great app, really enjoying it, keep it up!

LeoKlaus commented 4 months ago

Hey Primax, thanks for the bug report! Was plappa in the background (as in not fully closed) on device B? On startup, plappa tries to sync all playback states with the ABS server, always choosing the most recently updated value.

After that, playback states are pushed periodically while playing or when the user stops playback.

A check when the user taps the play button is possible, but could result in some significant delay while plappa waits for the server to respond.

I think the easiest solution would be to sync playback states whenever the app moves to the foreground (as in opened after not being fully closed).

I'll make an update ready and let you know once it's ready!

LeoKlaus commented 4 months ago

I've just published a new release (build 8) to TestFlight. You should be able to download it and test whether this fixes the issue.

Primax12 commented 4 months ago

Just tested the updated app, unfortunately the issue is still happening.

Was plappa in the background (as in not fully closed) on device B?

Nope, I avoided to have the app running on both device at the same time, so took care to close them (swiped the app up in the app switcher) when switching devices.

I think it is also reproductible with one device:

  1. Kill Plappa on device and close ABS tab.
  2. Open Plappa on device and start listening to a book.
  3. Pause progress and kill the app on device.
  4. Check in ABS, the progress has been updated.
  5. Listen a bit to the book in ABS frontend (browser) until progress has been updated (takes some time in the web UI) and close the tab.
  6. Reopen Plappa on the device (doesn't need to play the book).

With those steps the same issue appears, the app overrides the progress on ABS and resumes where you left on the device.

I think the easiest solution would be to sync playback states whenever the app moves to the foreground (as in opened after not being fully closed).

Indeed that would be more elegant.

LeoKlaus commented 4 months ago

Wow, you sent me down one crazy rabbit hole :D

Turns out there were a bunch of issues with playback state sync with ABS. I'm still not done correcting all of them but I definitely found the underlying issue. I'll let you know once I have an update ready.

LeoKlaus commented 4 months ago

I've just released an update to TestFlight (build no. 9) that should address the issue.

Primax12 commented 4 months ago

Glad you found the cause of issue and fixed it :) Just tested, and it's working perfectly now!

Thanks for all the time invested in the app, much appreciated!

LeoKlaus commented 4 months ago

Thanks for the update, great to hear!

LeoKlaus commented 2 months ago

Hey @Primax12 I'd like to send you a promo code for the AppStore version of plappa to thank you for your feedback. Any way I can send you a message? You can also just send me a quick mail at leo@plappa.me!