mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-26 00:31:20 -08:00
添加字幕插件
This commit is contained in:
1 parent
5f384fb04d
commit
1667457188
24 files changed
+492
-247
No files matched your search
@@ -0,0 +1,33 @@
|
||||
function artplayerPluginSubtitle(option) {
|
||||
return art => {
|
||||
const { errorHandle, clamp, sleep } = art.constructor.utils;
|
||||
|
||||
errorHandle(
|
||||
option && typeof option.time === 'number',
|
||||
`The plugin 'artplayerPluginSubtitle': 'option.time' require 'number' type, but got '${typeof option.time}'`,
|
||||
);
|
||||
|
||||
let retry = 0;
|
||||
const maxRetry = 10;
|
||||
const time = clamp(option.time, -10, 10);
|
||||
|
||||
function adjust() {
|
||||
errorHandle(retry < maxRetry, 'It seems that something wrong for reading subtitle');
|
||||
retry += 1;
|
||||
const cues = Array.from(art.refs.$track.track.cues);
|
||||
if (cues.length === 0) {
|
||||
sleep(100).then(adjust);
|
||||
} else {
|
||||
cues.forEach(cue => {
|
||||
cue.startTime += time;
|
||||
cue.endTime += time;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
art.on('subtitle:load', adjust);
|
||||
};
|
||||
}
|
||||
|
||||
window.artplayerPluginSubtitle = artplayerPluginSubtitle;
|
||||
export default artplayerPluginSubtitle;
|
||||
Reference in new issue
Block a user