Finally managed to sync up the UI to the API (with manual updates via a get button)! Created a State variable for position in Playhead (to allow for locally adjusting the position), that can be set to the state of the Spotify object when the refresh button is pressed.

Later I’ll add a timer/publisher to call this function periodically, but first I want to make sure I can send the position back to the API.

TODO: There’s lots of potential for fatal errors:

  • force unwrapping an optional before its populated by the Publishers)
  • Trying to run where there is no song playing
  • etc.

Tomorrow: Use the API to seek to the new position Next: Loops! Thinking about it now, the accuracy of the loop will depend on how quickly I poll the API. I can play with different polling intervals, but there will always be some inherent latency due to the asynchronous download. The iOS API will be less laggy, but still has that same issue that it needs polling continually. Another option would be to use a local timer that fires after the duration of the loop. - this could work better, because as long as the network lag (or local if using the iOS API) is relatively consistent, it should be able to create a stable loop.

Tags:

Categories:

Updated: