We run a meeting app on LiveKit (livekit-client2.16, Next.js). The host can share a video or audio link, either a YouTube link or a direct MP4/audio file, and everyone should see and hear it in sync.
What we do now
- Every participant’s browser plays the link itself, using a player component (react-player). The video is not published into the room.
- The host’s player broadcasts small
SYNC_MEDIAmessages over the LiveKit data channel: start, play, pause, seek, stop, and a periodic position snapshot about every 10 seconds. - Participants apply those messages. If their position differs from the host’s by more than~0.6 seconds, they seek.
- A late joiner asks the host for the current state when they connect.
- Messages carry the sender’s timestamp so receivers can compensate for network delay. We hit a bug where this assumed the two computers’ clocks agree. We now estimate the delay without assuming that.
Where it breaks Because every browser plays the media itself, every browser’s media rules apply to every viewer:
- Desktop Chrome and Safari: a share that starts while the viewer’s tab is in the background doesn’t play until they return to the tab. A share already playing keeps going if they switch away.
- Android Chrome and mobile Safari: playback pauses as soon as the viewer leaves the tab, even if it was already playing. On return, the picture jumps forward with the sync corrections but stays paused until the host pauses and plays again. We’ve added a fix that resumes playback when the tab becomes visible again, but the audio can’t continue in the background.
- Safari: needs a user tap before audio can play, and the embedded YouTube player is the least predictable.
- Sync drift: position drifts when viewers buffer or load at different speeds, and recovering depends on the periodic snapshots.
- We tested Windows Chrome, macOS Safari and Android Chrome. All show some form of problem, with different symptoms.
What we’ve considered
- Publish the media into the room instead, so viewers receive it as ordinary call audio and video, which keeps playing in background tabs. For direct MP4/audio links, LiveKit Ingress with a URL input looks like the right fit. Per the docs, it pulls a file from an HTTP server (HLS, MP4 and others), transcodes it, and publishes it as a participant. Viewers subscribe like any other track.
- Capturing the host’s player in the browser and publishing that track. This seems blocked for YouTube because the player runs in a cross-origin iframe.
Questions
- For direct media URLs, is Ingress URL input the recommended way to share a video with everyone? Any experience with latency, start-up time, or how pause, seek and stop are handled? Does the Ingress participant interact well with recording (egress) and with e2ee rooms?
- How do people handle seek and pause for an Ingress source? Does the Ingress participant support them, or do you need to recreate the ingress?
- For YouTube specifically, is there a better approach than each client embedding its own player and syncing over data messages? We understand embedding is required by YouTube’s terms and capturing isn’t possible.
- Is there a recommended pattern for keeping shared-media playback going when a mobile browser tab is hidden, or is “return to the tab” the best anyone can do?
- If you’ve built synced playback over data messages, any advice on the sync approach: snapshot interval, drift tolerance, handling clock differences between devices?
Happy to share more details or logs. Thanks!