This commit is contained in:
Harvey authored and Harvey Zack committed 2022-02-11 11:20:54 +08:00
1 parent 814a02d14a
commit dabfb2b8c8
10 files changed
+133 -173

No files matched your search

+1 -1
View File
@@ -37,6 +37,6 @@
"Fullscreen not supported": "不支持全屏模式",
"Local Subtitle": "本地字幕",
"Local Video": "本地视频",
"Subtitle offset time": "字幕偏移时间",
"Subtitle offset time": "字幕偏移",
"No subtitles found": "未发现字幕"
}
+1 -1
View File
@@ -37,6 +37,6 @@
"Fullscreen not supported": "不支持全屏模式",
"Local Subtitle": "本地字幕",
"Local Video": "本地視頻",
"Subtitle offset time": "字幕偏移時間",
"Subtitle offset time": "字幕偏移",
"No subtitles found": "未發現字幕"
}
+2
View File
@@ -28,6 +28,7 @@ import autoHeightMix from './autoHeightMix';
import themeMix from './themeMix';
import titleMix from './titleMix';
import exclusiveMix from './exclusiveMix';
import subtitleOffsetMix from './subtitleOffsetMix';
import optionInit from './optionInit';
import eventInit from './eventInit';
@@ -63,6 +64,7 @@ export default class Player {
themeMix(art);
titleMix(art);
exclusiveMix(art);
subtitleOffsetMix(art);
eventInit(art);
optionInit(art);
}
@@ -0,0 +1,39 @@
import { def } from '../utils';
export default function subtitleOffsetMix(art) {
const { clamp } = art.constructor.utils;
const { notice, template, i18n, subtitle } = art;
let cuesCache = [];
art.on('subtitle:switch', () => {
cuesCache = [];
});
def(art, 'subtitleOffset', {
set(value) {
if (template.$track && template.$track.track) {
const cues = Array.from(template.$track.track.cues);
const time = clamp(value, -5, 5);
for (let index = 0; index < cues.length; index++) {
const cue = cues[index];
if (!cuesCache[index]) {
cuesCache[index] = {
startTime: cue.startTime,
endTime: cue.endTime,
};
}
cue.startTime = clamp(cuesCache[index].startTime + time, 0, art.duration);
cue.endTime = clamp(cuesCache[index].endTime + time, 0, art.duration);
}
subtitle.update();
notice.show = `${i18n.get('Subtitle offset time')}: ${value}s`;
art.emit('subtitleOffset', value);
} else {
notice.show = `${i18n.get('No subtitles found')}`;
art.emit('subtitleOffset', 0);
}
},
});
}
-5
View File
@@ -1,5 +1,4 @@
import { errorHandle, has, def } from '../utils';
import subtitleOffset from './subtitleOffset';
import localVideo from './localVideo';
import localSubtitle from './localSubtitle';
import miniProgressBar from './miniProgressBar';
@@ -11,10 +10,6 @@ export default class Plugins {
const { option } = art;
if (option.subtitle.url && option.subtitleOffset) {
this.add(subtitleOffset);
}
if (!option.isLive && option.miniProgressBar) {
this.add(miniProgressBar);
}
@@ -1,84 +0,0 @@
import { query } from '../utils';
function settingMix(art) {
const {
i18n,
subtitle,
events: { proxy },
} = art;
return {
title: 'Subtitle',
name: 'subtitleOffset',
index: 20,
html: `
<div class="art-setting-header">
${i18n.get('Subtitle offset time')}: <span class="art-subtitle-value">0</span>s
</div>
<div class="art-setting-range">
<input class="art-subtitle-range" value="0" type="range" min="-5" max="5" step="0.5">
</div>
`,
mounted: ($setting) => {
const $range = query('.art-setting-range input', $setting);
const $value = query('.art-subtitle-value', $setting);
proxy($range, 'change', () => {
const { value } = $range;
$value.innerText = value;
art.plugins.subtitleOffset.offset(Number(value));
});
art.on('subtitle:switch', () => {
$range.value = 0;
$value.innerText = 0;
});
art.on('subtitleOffset', (value) => {
subtitle.update();
if ($range.value !== value) {
$range.value = value;
$value.innerText = value;
}
});
},
};
}
export default function subtitleOffset(art) {
const { clamp } = art.constructor.utils;
const { setting, notice, template, i18n } = art;
setting.add(settingMix);
let cuesCache = [];
art.on('subtitle:switch', () => {
cuesCache = [];
});
return {
name: 'subtitleOffset',
offset(value) {
if (template.$track && template.$track.track) {
const cues = Array.from(template.$track.track.cues);
const time = clamp(value, -5, 5);
for (let index = 0; index < cues.length; index++) {
const cue = cues[index];
if (!cuesCache[index]) {
cuesCache[index] = {
startTime: cue.startTime,
endTime: cue.endTime,
};
}
cue.startTime = clamp(cuesCache[index].startTime + time, 0, art.duration);
cue.endTime = clamp(cuesCache[index].endTime + time, 0, art.duration);
}
notice.show = `${i18n.get('Subtitle offset time')}: ${value}s`;
art.emit('subtitleOffset', value);
} else {
notice.show = `${i18n.get('No subtitles found')}`;
art.emit('subtitleOffset', 0);
}
},
};
}
+6
View File
@@ -3,6 +3,7 @@ import { append, addClass, setStyle, inverseClass } from '../utils/dom';
import playbackRate from './playbackRate';
import aspectRatio from './aspectRatio';
import flip from './flip';
import subtitleOffset from './subtitleOffset';
function makeRecursion(option) {
if (!option) return option;
@@ -50,6 +51,10 @@ export default class Setting extends Component {
this.option.push(flip(art));
}
if (option.subtitleOffset) {
this.option.push(subtitleOffset(art));
}
this.option = makeRecursion(this.option);
art.once('ready', () => {
@@ -119,6 +124,7 @@ export default class Setting extends Component {
}
add(callback) {
console.log(callback);
this.option.push(callback(this.art));
this.option = makeRecursion(this.option);
this.init(this.option);
@@ -0,0 +1,17 @@
export default function subtitleOffset(art) {
const { i18n } = art;
return {
width: 150,
html: i18n.get('Subtitle offset time'),
items: [-5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5].map((item) => {
return {
html: item === 0 ? i18n.get('Normal') : item,
current: item === 0,
click() {
art.subtitleOffset = item;
},
};
}),
};
}