Skip to content

Commit

Permalink
feat: 更新字幕插件版本;
Browse files Browse the repository at this point in the history
  • Loading branch information
hongqiongxing-b committed Oct 12, 2021
1 parent fc46c67 commit ee8bebc
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 8 deletions.
2 changes: 1 addition & 1 deletion packages/xgplayer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"draggabilly": "^2.2.0",
"event-emitter": "^0.3.5",
"fs-extra": "^5.0.0",
"xgplayer-subtitles": "^1.0.16"
"xgplayer-subtitles": "^1.0.19"
},
"browserslist": [
"> 5%",
Expand Down
11 changes: 7 additions & 4 deletions packages/xgplayer/src/controls/textTrack.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ class XgSubtitles {
return this.subtitle.switchOff()
}

setSubTitles (subtitles) {
return this.subtitle.setSubTitles(subtitles)
setSubTitles (subtitles, showDefault, isNeedMove) {
return this.subtitle.setSubTitles(subtitles, showDefault, isNeedMove)
}

onFocus () {
Expand Down Expand Up @@ -129,16 +129,19 @@ let textTrack = function () {

this.subTitles = new XgSubtitles(player, player.config.textTrack, textTrackStyle)

player.setSubTitles = (textTrack) => {
player.setSubTitles = (textTrack, needRemove = true) => {
let showDefault = false
textTrack.map((item, index) => {
if (!item.id && !item.language) {
item.id = index
}
!item.url && (item.url = item.src)
!item.language && (item.language = item.srclang)
item.isDefault === undefined && (item.isDefault = item.default)
item.isDefault && (showDefault = true)
})
this.subTitles.setSubTitles(textTrack)
player.textTrackShowDefault = showDefault
this.subTitles.setSubTitles(textTrack, showDefault, needRemove)
player.emit('subtitle_change', {
off: false,
isListUpdate: true,
Expand Down
17 changes: 14 additions & 3 deletions packages/xgplayer/src/skin/controls/textTrack.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ import { createDom, addClass, removeClass, hasClass } from '../../utils/util'
import '../style/controls/textTrack.scss'

function renderList (root, textTrack, offText, isDefaultShow) {
if (textTrack.length === 0) {
root.innerHTML = ''
return
}
let tmp = []
tmp.push(`<li data-type="off" class="${isDefaultShow ? '' : 'selected'}">${offText}</li>`)
textTrack.forEach(item => {
Expand All @@ -16,7 +20,7 @@ let s_textTrack = function () {
if (!this.config.textTrack) {
return
}
const { textTrack } = this.config
let textTrack = this.config.textTrack
let controlText = player.lang.TEXTTRACK
const container = createDom('xg-texttrack', `<ul></ul><p class="name">${controlText}</p>`, {tabindex: 7}, 'xgplayer-texttrack')

Expand Down Expand Up @@ -76,21 +80,28 @@ let s_textTrack = function () {

const ul = container.getElementsByTagName('ul')[0]
renderList(ul, textTrack, player.lang.OFF, player.textTrackShowDefault)
if (textTrack.length === 0) {
addClass(container, 'xgplayer-texttrack-hide')
} else {
removeClass(container, 'xgplayer-texttrack-hide')
}
}

const onListUpdate = function (data) {
if (!data.isListUpdate) return
const ul = container.getElementsByTagName('ul')[0]
textTrack = data.list
renderList(ul, data.list, player.lang.OFF, player.textTrackShowDefault)
data.list.length > 0 ? addClass(player.root, 'xgplayer-is-texttrack') : removeClass(player.root, 'xgplayer-is-texttrack')
if (data.list.length === 0) {
addClass(container, 'xgplayer-texttrack-hide')
} else {
removeClass(container, 'xgplayer-texttrack-hide')
}
}

if (textTrack && Array.isArray(textTrack) && textTrack.length > 0) {
addClass(player.root, 'xgplayer-is-texttrack')
if (textTrack && Array.isArray(textTrack)) {
textTrack.length > 0 && addClass(player.root, 'xgplayer-is-texttrack')
player.once('canplay', onCanPlay)
player.on('subtitle_change', onListUpdate)
}
Expand Down

0 comments on commit ee8bebc

Please sign in to comment.