如何播放YouTube视频同步在多个客户端? [英] How to play YouTube videos in sync on multiple clients?

查看:265
本文介绍了如何播放YouTube视频同步在多个客户端?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望了解如何建立一个Web应用程序,允许多个用户可以查看自己的电脑一样的YouTube视频同步。例如, synchtube.com watch2gether.com

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 watch2gether.com

我正在寻找可以使用通用的技术来实现,例如 PHP 的jQuery 和一个简单的方法阿帕奇。目前,我正在沿着投票的行思(或彗星长轮询但需要更复杂的服务器设置,我希望避免),类似于如何阿贾克斯聊天应用程序中实现 - 这是客户不断与服务器进行检查,看看它的视频播放。不过,我怀疑会有延迟问题在这里,所以影片不会完全同步。我想不出更好的方法呢。

I'm seeking a simple approach that can be implemented using common technologies such as PHP, jQuery and Apache. I'm currently thinking along the lines of polling (or comet long polling but that requires more complex server setup which I hope to avoid), similar to how Ajax chat apps are implemented - that is clients continuously check with the server to see which video is playing. However, I suspect there will be latency issues here so videos will not be completely in sync. I can't think of a better approach yet.

要同胞的开发者社区,在方法或code片段的任何帮助都是巨大的AP preciated!

To fellow developer community, any help on the methodology or code snippets are hugely appreciated!

推荐答案

下面是一个使用的WebSockets和Node.js的保持视频同步的例子: http://softwareas.com/video-sync-with-websocket-and-node

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

我知道你不希望使用此技术,它只是一个很好的起点,以显示你可以做什么,以及如何。

由于要使用PHP和让事情变得简单,然后你最好的解决方案是将实时通信层(用来保持同步用户视频),以托管服务外包等的,谁我工作。这意味着你不需要保持持久连接,你可以使用推杆来提供有关用户/客户端之间的视频状态的实时事件。

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.

如果你想使用YouTube视频,而HTML5并不总是将是可用的,那么你就需要使用的播放器API 。我不能看到类似的 timeupdated 事件(可在HTML5视频),所以你可能需要周期性地检查视频时间(见的播放器状态API部分,你可以注册状态更改事件,让你知道当用户暂停,停止一视频等。

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.

@抢-W的评论提供了一些很好的洞察力使用YouTube API。

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

注:这实际上可能使一个非常有趣的博客文章,所以如果你有兴趣让我知道,我会看看我能做些什么

这篇关于如何播放YouTube视频同步在多个客户端?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆