How to play YouTube videos in sync on multiple clients?

后端 未结 3 1965
执笔经年
执笔经年 2020-12-13 11:04

I\'m looking to understand how to build a web app that allows multiple users to view the same YouTube video in sync on their computers. For example, synchtube.com or watch2g

3条回答
  •  一整个雨季
    2020-12-13 11:55

    Here's an example of keeping videos in sync using WebSockets and node.js: http://softwareas.com/video-sync-with-websocket-and-node

    I know you don't want to use this tech, it's just a good starting point to show what you can do and how.

    Since you want to use PHP and keep things simple then your best solution is to outsource the realtime communications layer (used to keep the user videos in sync) to a hosted service such as Pusher, who I work for. This means you don't need to maintain the persistent connection and you can use Pusher to deliver realtime events about the video states between users/clients.

    If you want to use YouTube videos, and HTML5 isn't always going to be available, then you'll need to use the Player API. I can't see a similar timeupdated event (available in HTML5 video) so you might need to periodically check the video time (see player status API section. You can register for state change events so you know when a user pauses, stops a video etc.

    @rob-w's comment provides some good insight into using the YouTube API.

    Note: This might actually make for a really interesting blog post so if you are interested let me know and I'll see what I can do.

提交回复
热议问题