0x213F / jukebox-radio-django

Part Jukebox. Part Radio.
Other
1 stars 0 forks source link

Playback: calibrate stream time #76

Closed 0x213F closed 3 years ago

0x213F commented 3 years ago

Summary

The playback engine has been working great so far!

The backend Stream model keeps track of started_at for now_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 played 30 seconds ago. The front-end knows to start playing the Hello, world! track starting at the 30 second mark.

One catch...

So let's say the front-end plays Hello, world! starting at the 30 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 the stream object. The stream object can be fetched with the following:

stream = Stream.objects.get(user=request.user)

By the way...

The lag is real (I am looking at you Apple Music), otherwise this ticket would not exist.

0x213F commented 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.