Closed 0x213F closed 3 years ago
Ok so good news, I don't think there needs to be any additional code changes on the backend! The FE can simply use the scan
endpoint. Since the playback engine on the FE allows for faking the playback engine layer and faking the API layer, all we need to do is do a fake scan on the playback engine layer and a non-fake API scan. This will re-sync the client with the BE.
Closing.
Summary
The playback engine has been working great so far!
The backend
Stream
model keeps track ofstarted_at
fornow_playing
. This key combination allows the front-end to determine what is playing and when it was played.For example, consider the case where the front-end loads the application and sees that the track
Hello, world!
was played30 seconds ago
. The front-end knows to start playing theHello, world!
track starting at the30 second
mark.One catch...
So let's say the front-end plays
Hello, world!
starting at the30 second
mark. However, due to reasons (let's say slow internet connection + server lag), let's say that there is a 1 second delay between when the front-end "plays" the song and when the song actually starts playing.This 1 second delay ends up making the client off sync with the server. The server thinks that the song was played 1 second before it was actually played. In order to remedy this scenario, the back-end needs a new POST API endpoint. Inside the endpoint, it will take one parameter:,
started_at
, which will have a timestamp (int) of the actual start time. This timestamp can simply be saved in thestream
object. Thestream
object can be fetched with the following:By the way...
The lag is real (I am looking at you Apple Music), otherwise this ticket would not exist.