system-76 / griffith

A React-based web video player

Home Page:https://codesandbox.io/embed/p03wm0o80

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

A React-based Web video player

License npm package Coverage Status Code style PRs Welcome

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 direct use 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 sources = {
  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 sources={sources} />)

Detailed usage

Note: Griffith is not supporting SSR application

non-React application

<script src="https://unpkg.com/griffith-standalone/dist/index.umd.min.js"></script>
const sources = {
  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({sources})

Standalone mode detailed usage

Project Structure

Griffith is a Monorepo and uses Yarn workspace and Lerna.

Core

  • packages/griffith: The core library

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 include griffith-mp4 and griffith-hls by default. You can make your bundle smaller by injecting aliases at build-time.

If you use webpack, do so with resolve.alias:

// webpack v5+
module.exports = {
  resolve: {
    alias: {
      'griffith-hls': false,
      'griffith-mp4': false,
    },
  },
}

// webpack v4
module.exports = {
  resolve: {
    alias: {
      'griffith-hls': 'griffith/null',
      'griffith-mp4': 'griffith/null',
    },
  },
}

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.

Contributing Guide

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

LICENSE

MIT

About

A React-based web video player

https://codesandbox.io/embed/p03wm0o80

License:MIT License


Languages

Language:TypeScript 95.2%Language:JavaScript 3.1%Language:CSS 1.4%Language:HTML 0.3%