xgplayer is a web video player library. It has designed a separate, detachable UI component based on the principle that everything is componentized. More importantly, it is not only flexible in the UI layer, but also bold in its functionality: it gets rid of video loading, buffering, and format support for video dependence. Especially on mp4 it can be staged loading for that does not support streaming mp4. This means seamless switching with clarity, load control, and video savings. It also integrates on-demand and live support for FLV, HLS, and dash. Document
xgplayer-react is the React component which encapsulating the xgplayer.
-
Install
$ npm install xgplayer-react@latest
-
Usage
Step 1. Add xgplayer-react component
import Xgplayer from 'xgplayer-react';
Step 2. Use in template
<Xgplayer config={config} playerInit={(player)=>{ Player = player; }} />
Step 3. Config for xgplayer
let config = { id: 'mse', url: '/xgplayer-demo.mp4' }; let Player = null;
You can use 'config' object to pre-config xgplayer, such as size, volume, autoplay and so on. More config
'mp4', 'hls', 'flv', 'dash' are supported to play and you should add the plugin you want to use. Functional Plugins List.
'Player' is the xgplayer instance which exposed from the component. You can use 'Player' to access the API of xgplayer as follows.
console.log(Player.currentTime)
Player.pause();
Player.on('play', ()=>{console.log('play')})
Player.once('ready', ()=>{console.log('ready')})
xgplayer supports your custom plugins for more content viewing plugins
import Xgplayer from 'xgplayer-react';
import 'xgplayer-custom';
$ git clone git@github.com:bytedance/xgplayer-react.git
$ cd xgplayer-react
$ npm install
$ npm start
please visit http://localhost:9090/index.html