Griffith 是一个基于 React 的视频播放器,目前已在知乎 web 和 mobile web 内使用,并在 GitHub 上开源。webpack
GitHub 地址:https://github.com/zhihu/grif...git
CodeSandbox 示例:https://codesandbox.io/s/74ol...github
Griffith 提供了简洁易用的播放器 UI。目前知乎网页端视频播放器就是使用的 Griffith。web
Griffith 参考 YouTube 进行了快捷键支持,后续还会添加更多的快捷键。npm
Griffith 是一个基于 React 开发的 web 视频播放器。对于 React 应用,能够直接经过组件调用的方式使用。浏览器
Griffith 使用 Context API 进行状态管理。对于 React 应用,能够经过引入 Griffith 的 Context 来实现弹幕等自定义功能。工具
对于非 React 应用,或者不肯意经过 npm 包安装的用户,Griffith 提供 standalone 模式能够免构建工具直接在浏览器中使用。单元测试
Griffith 定义了丰富的事件系统。测试
对于视频播放器中常见的首帧时长,缓冲次数等指标,能够经过接收 Griffith 事件来进行打点记录。url
对于一些须要与播放器进行通讯的功能,能够经过往 Griffith 发送事件来与播放器进行交互。
Griffith 使用了 Media Source Extensions™ ,支持对 mp4 和 m3u8 格式的视频进行流式播放。
import Player from 'griffith' const sources = { hd: { play_url: 'https://zhstatic.zhihu.com/cfe/griffith/zhihu2018hd.mp4', }, sd: { play_url: 'https://zhstatic.zhihu.com/cfe/griffith/zhihu2018sd.mp4', }, } render(<Player sources={sources} />)
<div id="player"></div> <script src="https://unpkg.com/griffith-standalone/dist/index.umd.min.js"></script> <script> const target = document.getElementById('player') const sources = { hd: { play_url: 'https://zhstatic.zhihu.com/cfe/griffith/zhihu2018hd.mp4', } , sd: { play_url: 'https://zhstatic.zhihu.com/cfe/griffith/zhihu2018sd.mp4', }, } // 建立播放器 const player = Griffith.createPlayer(target) // 载入视频 player.render({sources}) // 销毁视频 player.dispose() </script>
Griffith 全部的工做都会在 GitHub 上进行(知乎内部使用的也是同一个仓库)。若是有任何相关的疑问和 bug,欢迎在 GitHub 提交 issue、PR 帮助 Griffith 变得更好。