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

xgplayer-flv

FLV plugin provided by xgplayer makes it possible to play video in FLV format without Flash

xgplayer-flv

Install

npm i xgplayer@version --save
npm i xgplayer-flv@version --save

import Player from 'xgplayer'
import FlvPlayer from 'xgplayer-flv'

CDN

<link rel="stylesheet" href="https://unpkg.byted-static.com/xgplayer/@version/dist/index.min.css"/>
<script src="https://unpkg.byted-static.com/xgplayer/@version/dist/index.min.js"></script>
<script src="https://unpkg.byted-static.com/xgplayer-flv/@version/dist/index.min.js"></script>

Usage

  const player = new Player({
      id: 'vs',
      plugins: [FlvPlayer],
      url: 'index.flv',
      isLive: true | false,
      flv:{
        loadTimeout: 10000,
        preloadTime: 4,
        retryCount: 2,
        retryDelay: 1000
      }
    });

Config

Config of plugin specialized passed by flv:{} when init player

xgplayer-flv

NameDescriptionDefault value
retryCountMax retry number for network error by millisecond3(s)
retryDelayTime between every single retry action by second0(ms)
loadTimeoutMax waiting time for loading flv stream by millisecond10000(ms)
seiOnDemandif emit sei info follow by currentTimefalse
optionsparams used by fetch api{headers:{}, cors: true, withCredentials:false}
preloadTimeTarget buffer size for anti-jitter by second5(s)

options

NameDescription
options.headersrequest header append to fetch
options.corscors mode
options.withCredentialsis request with credentials

Api

function
pause()
play()
replay()
switchURL(url), player.src = url

Events

For flvplayer、hlsplayer, we provide a series of core event, which exposing essential information for you to monitor and report

player.on('{coreEvent}', coreInfo=>{

})

Structure of coreInfo:

NameTypeDescription
eventNamestringName of core event
...-other properties depend on event name

Provided Core Events

core.ttfb

Cost of first frame

NameTypeDescription
eventNamestring--
startnumberRequest start time
endnumberRequest end time
urlstringRequest URL
elapsednumberCost by ms

core.loadstart

Starting for load stream

NameTypeDescription
eventNamestring--
urlstringRequst URL

core.loadresponseheaders

Response headers

NameTypeDescription
eventNamestring--
headersHeadersSame with Response.header

core.loadcomplete

Load Complete

NameTypeDescription
eventNamestring--

core.loadretry

Retry for loading stream

NameTypeDescription
eventNamestring--
reasonstringPrevious request failed reason
retryTimenumberRetry count
error{code, message}Error from previous request

core.keyframe

Raw pts from parsed keyframe

NameTypeDescription
eventNamestring--
ptsnumberPersent time stamp of keyframe

core.metadataparsed

Metadata of video tracks

NameTypeDescription
eventNamestring--
type"video" or "audio"metadata type
metaobjectMetadata object

core.remuxmetadata

Metadata was remuxed by player

NameTypeDescription
eventNamestring--
type"video""audio"

core.bufferappend

Remuxed buffer appended to MediaSource

NameTypeDescription
eventNamestring--

core.seiparsed

SEI Nal parsed

NameTypeDescription
eventNamestring--
sei{code:number, content: Uint8Array, dts:number}SEI details

core.lowdecode

For WASM playback, decode speed is lower than video FPS

NameTypeDescription
eventNamestring--
fpsnumber
decodeFpsnumberDecode speed by fps
bitratenumberVideo bitrate (bps)
urlnumberPlayback url
msg (optional)stringDecode error message

core.largeavgap

Video dts was distant from audio’s, may cause avunsync

NameTypeDescription
eventNamestring--

core.streamexception

Unexpected stream expection, for example: frame lossed、dts stepback

NameTypeDescription
eventNamestring--
typestringException message
infoobjectDetail info

core.streamexception

typeMessage
LARGE_AV_FIRST_FRAME_GAP_DETECTLarge gap between audio and video was detected, may causes avunsync
LARGE_VIDEO_DTS_GAP_DETECTVideo dts discontiune detected
LARGE_AUDIO_DTS_GAP_DETECTAudio dts discontiune detected
AUDIO_GAP_DETECTPlayer fix audio gap by filling silence frames in
AUDIO_OVERLAP_DETECTPlayer fix audio gap by dropping overlaped frames
VIDEO_DISCONTINUE_DETECTDiscontinue m3u8 tag found
MAX_DTS_DELTA_WITH_NEXT_SEGMENT_DETECTLarge dts gap between m3u8 ts fragments found