西瓜播放器 HTML5 video video.js 播放器 HTML5播放器 mp4 hls hls.js flv flv.js dash dash.js 无缝切换

Plugins

The design of xgplayer is based on plugin system, all of built-in components are developed as plugins, so it is really important for you to learn about the mechanism of plugin for better customizing the player.

Get plugin instance from player

// get pip instance
const pipInstance = player.getPlugin('pip')
// or
const pipInstance = player.plugins.pip

// Enter PIP mode by invoking API
pipInstance.switchPIP()

Plugin registeraion

Pass plugin to player by config:

import DemoPlugin from 'demoplugin'
import Player from 'xgplayer'

const player = new Player({
  ...,
  plugins: [DemoPlugin]
})

Dynamic registration

import DemoPlugin from 'demoplugin'
import Player from 'xgplayer'

const player = new Player({
  ...
})
player.registerPlugin(DemoPlugin)

Ignore plugins

  const player = {
    ...,
    ignores: ['play']
  }

Deregister plugin

In most of cases, you don't need to deregister plugins manually, but if it's really needed, you can do it by unRegisterPlugin API

player.unRegisterPlugin('pluginame')

Built-in plugins

NameDescription
controlsControl bar
progressProgress bar
progresspreviewPreviewer
mobileUser gesture for mobile devices
pcUser gesture for PC browsers
definitionChange definition
errorError feedback
fullscreenFullscreen button
cssfullscreenCSS-fullscreen button
loadingLoading
playPlay/pause button
posterPoster
enterLoading for first frame
replayReplay button
startBig play/pause button (placed to center of playing area)
volumeVolume control bar
timeCurrent time / Duration
playbackrateplayback speed selection button
pippicture-in-picture toggle button