1.31.0 • Published 2 months ago

griffith v1.31.0

Weekly downloads
64
License
MIT
Repository
-
Last release
2 months ago

griffith

English | 简体中文

Usage

yarn add griffith
# Griffith uses hls.js to play m3u8 format video.
# If you don't want to install hls.js, please ref the build part.
import Player from 'griffith'

render(<Player {...props} />)

Props

NameTypeDefaultDescription
idstringUnique identifier of the player instance
titlestringVideo title
coverstringVideo cover image
durationnumberInitial video duration. Use actual values after video metadata is loaded
sourcessourcesVideo playback data
defaultQualityld \| sd \| hd \| fhdVideo default quality
defaultQualityOrderasc \| descascthe order for selecting default quality
useAutoQualitybooleanfalseEnable auto quality
standalonebooleanfalseEnable standalone mode
enableCrossWindowMessagebooleanfalseEnable send messages cross window, the parent page can communicate with player in iframe.Has the highest priority-first
onBeforePlayfunctionvoidCallback function before video playback
onEvent(type: string) => voidvoidCallback function when common event is triggered
shouldObserveResizebooleanfalseListen to the window resize
initialObjectFitfill \| contain \| cover \| none \| scale-downcontainobject-fit
useMSEbooleanfalseEnable Media Source Extensions™
localeen \| ja \| zh-Hans \| zh-HantenUI Locale
autoplaybooleanfalseAutoplay
mutedbooleanfalseMuted
disablePictureInPicturebooleanfalseDisable Picture in Picture feature
hiddenPlayButtonbooleanfalseHide play button
hiddenTimelinebooleanfalseHide progress bar
hiddenTimebooleanfalseHide duration and total time
hiddenQualityMenubooleanfalseHide quality menu (if it is shown)
hiddenVolumebooleanfalseHide volume
hiddenFullScreenButtonbooleanfalseHide full screen button
progressDotsProgressDotItem[][]Node information on the progress bar

sources:

interface sources {
  [key in ('ld' | 'sd' | 'hd' | 'fhd')]: {
    bitrate?: number
    duration?: number
    format?: string
    height?: number
    width?: number
    play_url: string
    size?: number
  }
}

progressDots:

type ProgressDots = ProgressDotItem[]

interface ProgressDotItem {
  startTime: number (second)
}

Standalone mode

The standalone mode indicates that the player is the only content of the document and is generally used as an internal page of the iframe.

The behavior in standalone mode is:

  • Will set the title of the document to the title of the video.
  • Enable shortcut support (listen to the keydown event on document).
  • Will send a message to the parent page, the parent page can listen to these events and then communicate with the player.

Cross-window message with player

use griffith-message

Build Options

We rely on hls.js to play M3U8 format video. If you don't want to build hls.js into your app, you can use the following methods:

Use the external option of webpack

Add the following options to your webpack configuration:

externals: {
  'hls.js/dist/hls.light.min': 'Hls',
},

Then manually load hls.js in html:

<script src="https://unpkg.com/hls.js@0.7.11/dist/hls.light.min.js"></script>

Remove M3U8 support

If you are sure that you will not support M3U8 video, you may not use hls.js.

Add the following options to your webpack configuration:

resolve: {
  alias: {
    'griffith-hls': false,
  },
},

Note: In this case, an error warning is issued if an attempt is made to play an M3U8 video.

technical details

formatparseMedia Source Extension (MSE)
M3U8HLShls.js
mp4griffith-mp4griffith-mp4.js

Confirm whether HLS is supported

document.createElement('video').canPlayType('application/vnd.apple.mpegURL')

Currently supported browsers are: Safari, Edge, Chrome, Chrome for Android.

Confirm whether MSE is supported

hls.js's Hls.isSupported() method is used to determine whether MSE is supported.

function getMediaSource() {
  if (typeof window !== 'undefined') {
    return window.MediaSource || window.WebKitMediaSource
  }
}

function isSupported() {
  const mediaSource = getMediaSource()
  const sourceBuffer = window.SourceBuffer || window.WebKitSourceBuffer
  const isTypeSupported =
    mediaSource &&
    typeof mediaSource.isTypeSupported === 'function' &&
    mediaSource.isTypeSupported('video/mp4; codecs="avc1.42E01E,mp4a.40.2"')

  // if SourceBuffer is exposed ensure its API is valid
  // safari and old version of Chrome doe not expose SourceBuffer globally so checking SourceBuffer.prototype is impossible
  const sourceBufferValidAPI =
    !sourceBuffer ||
    (sourceBuffer.prototype &&
      typeof sourceBuffer.prototype.appendBuffer === 'function' &&
      typeof sourceBuffer.prototype.remove === 'function')
  return !!isTypeSupported && !!sourceBufferValidAPI
}

Support details: https://caniuse.com/#feat=mediasource

Video quality switching

The API returns multiple quality URLs, users can manually switch video quality, and the player can automatically switch video quality.

Development

yarn
yarn start

Open the player page: http://localhost:8000

1.31.0

2 months ago

1.30.0

1 year ago

1.29.0

2 years ago

1.27.3

2 years ago

1.28.0

2 years ago

1.27.2

2 years ago

1.27.0

2 years ago

1.27.1

2 years ago

1.26.2

2 years ago

1.26.1

2 years ago

1.25.1

2 years ago

1.26.0

2 years ago

1.25.0

2 years ago

1.24.3-beta.0

2 years ago

1.24.1

2 years ago

1.24.2

2 years ago

1.24.3

2 years ago

1.23.0-beta.0

2 years ago

1.23.0

2 years ago

1.22.0

2 years ago

1.22.1

2 years ago

1.24.0

2 years ago

1.23.0-beta.1

2 years ago

1.23.0-beta.2

2 years ago

1.21.3

3 years ago

1.21.2

3 years ago

1.21.1

3 years ago

1.21.0

3 years ago

1.20.0

3 years ago

1.18.4

3 years ago

1.18.4-beta.2

3 years ago

1.18.5-beta.0

3 years ago

1.18.5-beta.1

3 years ago

1.19.0

3 years ago

1.18.3

3 years ago

1.18.4-beta.1

3 years ago

1.18.4-beta.0

3 years ago

1.18.1

3 years ago

1.18.0

3 years ago

1.18.2

3 years ago

1.18.2-beta.0

3 years ago

1.7.0-beta.1

3 years ago

1.17.1

3 years ago

1.17.1-beta.0

3 years ago

1.17.1-beta.1

3 years ago

1.17.0-beta.0

3 years ago

1.17.0

3 years ago

1.16.0

3 years ago

1.15.0

3 years ago

1.15.1

3 years ago

1.14.2

3 years ago

1.14.1

3 years ago

1.14.0

3 years ago

1.13.0

3 years ago

1.12.0

3 years ago

1.11.1

3 years ago

1.11.0

3 years ago

1.10.0

3 years ago

1.9.0

4 years ago

1.8.1

4 years ago

1.8.0

4 years ago

1.7.0

4 years ago

1.6.0

4 years ago

1.5.3

4 years ago

1.5.2

4 years ago

1.5.1

4 years ago

1.5.0

5 years ago

1.4.5

5 years ago

1.4.4

5 years ago

1.4.3

5 years ago

1.4.2

5 years ago

1.4.1

5 years ago

1.4.0

5 years ago

1.3.1

5 years ago

1.3.0

5 years ago

1.2.1

5 years ago

1.1.7

5 years ago

1.1.6

5 years ago

1.1.4-beta.1

5 years ago

1.1.4-beta.0

5 years ago

1.2.0

5 years ago

1.1.5

5 years ago

1.1.4

5 years ago

1.1.3

5 years ago

1.1.2

5 years ago

1.1.1

5 years ago

1.0.0

5 years ago

1.1.0

5 years ago