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

+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);
}
},
});
}