Skip to content

katavii/griffith

Repository files navigation

React-based web video player

English | 简体中文

Introduction

  • Streaming: griffith makes streaming easy. Whether your video format is mp4 or hls, griffith can use Media Source Extension (MSE) for segment loading.
  • Extensibility: griffith makes it simple to support video features in React apps. It also supports the UMD (Universal Module Definition) patterns for use directly in the browser if your application is not based on React.
  • Reliability: griffith has been widely used in the web and mobile web of zhihu.

Usage

React application

$ yarn add griffith
import Player from 'Griffith'

const playlist = {
  hd: {
    play_url: 'https://zhstatic.zhihu.com/cfe/griffith/zhihu2018_hd.mp4',
  },
  sd: {
    play_url: 'https://zhstatic.zhihu.com/cfe/griffith/zhihu2018_sd.mp4',
  },
}

render(<Player playlist={playlist} />)

Detailed usage

Note: SSR application is not supported

non-React application

<script src="https://unpkg.com/griffith-standalone/dist/index.umd.min.js" /></script>
const playlist = {
  hd: {
    play_url: 'https://zhstatic.zhihu.com/cfe/griffith/zhihu2018_hd.mp4',
  },
  sd: {
    play_url: 'https://zhstatic.zhihu.com/cfe/griffith/zhihu2018_sd.mp4',
  },
}

Griffith.createPlayer(element).render({playlist})

Standalone mode detailed usage

Project Structure

Griffith is a mono-repo and use Yarn workspace and monorepo.

Core

  • packages/griffith: The core lirary

Utilities

  • packages/griffith-message: Helpers for cross-window message
  • packages/griffith-utils: Utilities

Plugins

Others

  • example: example and demos
  • packages/griffith-standalone: A UMD build that can be used without React or Webpack

Custom Build

Build tools like webpack will include griffith-mp4 and packages/griffith-hls by default. You can make your bundle smaller by exluding a plugin with build-time globals.

If you use webpack, do so with DefinePlugin:

const {DefinePlugin} = require('webpack')

module.exports = {
  plugins: [
    new DefinePlugin({
      __WITHOUT_HLSJS__: JSON.stringify(true), // exludes griffith-hls
      __WITHOUT_MP4__: JSON.stringify(true), // exludes griffith-mp4
    }),
  ],
}

Note that without griffith-mp4 / griffith-hls Griffith can no longer play MP4 / HLS media unless the browser supports it natively.

Contributing

Read below to learn how you can take part in improving griffith.

Read our contributing guide to learn about our development process, how to propose bugfixes and improvements, and how to build and test your changes to griffith.

Contributor

  • Cheng Wang
  • Wuhao Liu
  • Xiaoyan Li
  • Tianxiao Wang
  • Xiaoshuang Bai (Designer)

LICENSE

MIT

About

A React-based web video player

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 98.1%
  • CSS 1.6%
  • HTML 0.3%