-->
Save your FREE seat for 流媒体 Connect in November. 现在注册!

How to Build Online Video Players

Article Featured Image

As online video continues to increase in popularity, 越来越多的开发者和企业纠结于如何构建自己的在线视频应用程序. The variety of choices feels endless. 您应该使用现有的在线视频平台(OVP)提供商还是自己构建? Which platforms will you be able to support? Which features do you need? These choices and many others can seem overwhelming, but with careful planning, you can determine your answers and execute your choices.

Understanding the Choices Available

Before going too far into the exploration, there are certain basic business rules that need to be understood. 你需要一个流媒体播放器,还是渐进式下载是一个更好的选择?

渐进式下载

Progressive download is one of the easier features to support. 如今,所有HTML5浏览器都支持渐进式下载,作为H.264 -编码内容. 在选择此选项时,您应该了解渐进式下载实际需要什么.

渐进式下载允许将单个视频文件下载到客户端的计算机上,并在下载时播放. 它不需要等待整个文件下载完成后才开始播放, 但是你能够植入玩家的功能是非常有限的.

Adaptive bitrate (ABR) isn’t an option; progressive download only allows for one file to be played.

Seeking presents user experience problems on some platforms, 因为它暂停播放(缓冲),直到文件下载到用户正在寻找的点为止. This isn’t an issue on platforms such as HTML5, which can use byte range requests, allowing seeking to happen nearly instantaneously.

也, it becomes difficult to protect the content, since by the end of the video, the entire file is sitting in the user’s cache.

最终, 对于短视频(通常指长度少于10分钟的视频)来说,渐进式下载是一个可行的选择, 尽管绝大多数短视频都不超过2分钟,但这并不需要保护. 这样做的原因是短视频通常可以快速下载, which negates the seeking issues, and if the content does not require protection, the lack of content protection ceases to be an issue. 同样的, on videos only a few minutes in length, 大多数现代互联网连接将能够以单个比特率下载内容, which mitigates the lack of ABR.

如果内容不是短格式的,或者需要保护,您应该考虑流选项.

流媒体视频

流媒体视频的本质是视频的单个片段被下载并播放, as opposed to progressive download, which downloads the entire file. 流媒体的好处是,在任何视频片段被下载之前, you can decide what bitrate the player should play, 启用ABR逻辑. 另外, seeking becomes much easier with streamed content, as there is no requirement to download any skipped content, which allows for a much more responsive experience. If you start at the beginning, 观看30秒, then seek an hour forward, 您跳过的59分30秒不需要下载, 所以玩家可以无缝地从用户请求的新点继续游戏.

构建流媒体播放器的缺点是它本质上更复杂,因此需要更多的时间来构建和更多的代码来运行. 然而, for longform content and content which requires protection, streaming is a requirement in nearly all cases.

支持的平台

另一个常见的问题是,内容需要在哪个平台上播放. If you only need to support a desktop browser, 这意味着与你需要支持Android或iOS相比,复杂性有很大不同, 机顶盒, 连接电视, 或者是游戏机.

Some of these platforms provide HTML5-compliant browsers, which make progressive download an option, 然而, that is not true for all or even most of them. 应该理解的是,如果一个流应用程序需要跨多个平台, 它将, 最有可能的, require writing (or implementing, (如果您使用的是现成的OVP)几个不同的代码库.

Off-the-Shelf Players

现在市场上有很多值得你考虑的ovp和玩家. Among them are Brightcove’s Video.js、JWPlayer、创作的播放器、Ooyala的播放器、thePlatform的播放器和Adobe的Primetime播放器.

The available players, their licensing models, 它们支持的特性很可能在本文撰写和发布期间发生了变化. As you begin the process of building a video application, 您应该查看所有可用的选项,并确定其中是否有适合您需求的选项. If so, using an OVP is highly recommended. 然而, 有时候你会发现没有现成的解决方案是非常适合的, either for feature or economic reasons. 在这种情况下,创造自己的玩家便是最佳解决方案.

选择建造

After doing your research, 您可能会发现您的特定需求不适合任何现有的OVP解决方案. In that case, you will likely decide to build your own solution. 首先,您需要确定希望支持哪些平台以及希望使用哪些技术.

桌面解决方案

如果你需要你的视频可供消费者在他们的个人电脑上观看, you will need a desktop player. 虽然桌面支持的技术有着悠久而多样的历史, today there are three primary platforms: Adobe Flash, Microsoft Silverlight, 和HTML5.

越来越多地, companies are choosing to deploy a hybrid solution, 在第一个平台不可用的情况下,哪个平台优先考虑一个平台,并将故障转移到另一个平台. 例如, 有些人选择先在HTML5上尝试游戏, but if that is not available (for older browsers, 举个例子), 他们在Flash中尝试.

The hybrid solution most commonly combines Flash 和HTML5, 因为Silverlight目前在全球不到60%的台式机上可用, 而Adobe Flash仍然安装在超过90%的台式机中.

使用JavaScript, 您可以检测浏览器的功能,并确定哪个平台最适合用户.

闪光

To play video in Flash, you need an instance of the flash.媒体.视频类. This class can natively handle progressive downloaded video. With the addition of a streaming server, such as Adobe Media Server, or Wowza Streaming Engine, playback of streaming video is also possible.

要构建一个Flash视频播放器,您将需要一个类,类似于 图1.

要构建一个Flash视频播放器,您将需要一个类似的类. 

In the constructor of this class, 将创建NetConnection类的实例,并将事件侦听器添加到该实例. The connect method connects the Flash player to a 媒体 server. In this case, it is called and passed 作为论证, 表示文件是从本地文件系统或web服务器提供的,而不是从媒体服务器提供的. 当连接准备好时,NetConnection将触发一个NET_ STATUS事件.

流媒体覆盖
免费的
for qualified subscribers
现在就订阅 最新一期 过去的问题
相关文章

How to Build an HTML5 Video Player, from VideoJS's Creator

Steve Heffernan explains how to build a customized HTML5 player. Watch this for everything you need to know.

How to Build an HTML5 Video Player

两位年轻但经验丰富的HTML5视频专家告诉观众为什么他们应该使用HTML5视频,并指导他们完成所需的代码.

Companies and Suppliers Mentioned