Introduction
外挂字幕组件,目前支持vtt格式的解析
Start
-
Install
$ npm install xgplayer-subtitles
-
Usage
Step 1:
<div id="vs"></div>
Step 2:
import Player from 'xgplayer';
const player = new Player({
id: 'vs',
url: ''
})
const options = {
player: player,
subTitles: [{
label: '中文',
language : '',
id: 'cn',
isDefault: false,
url: './subtitle/cn.vtt'
}, {
label: '英文',
url: './subtitle/en.vtt',
id: 'en',
isDefault: true,
language: 'en'
}],
defaultOpen: false,
mode: 'bg',
line: 'double'
}
const subTitle = new window.XgSubtitle(options)
subTitle.attachPlayer(player)
API
atttchPlayer(player)
挂载播放器实例
detachPlayer(player)
卸载播放器实例
destroy
销毁组件
switch({id:'', language:''})
切换字幕
subtitle.switch({id: 'cn'}).then(() => {
console.log('切换成功')
}).catch(() => {
console.log('切换失败')
})
切换信息返回说明
{
code: 0,
msg: 'SUCCESS'
},{
code: 1,
msg: 'LOAD_ERROR'
}, {
code: 2,
msg: 'PARSER_ERROR'
}, {
code: 3,
msg: 'FORMAT_NOT_SUPPORTED'
},
{
code: 4,
msg: 'ID_OR_LANGUAGE_NOT_EXIST'
}, {
code: 5,
msg: 'PARAMETERS_ERROR'
}, {
code: 6,
msg: 'ABORT'
}, {
code: 7,
msg: 'UNKNOWN'
}
openOff()
关闭当前字幕
错误码说明