mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-20 12:11:20 -08:00
Refactor loadSubtitleAsVtt to use
art.constructor.utils
This commit is contained in:
1 parent
89b8525f2f
commit
783bf1cac3
2 files changed
+866
-857
No files matched your search
@@ -12,8 +12,8 @@ function unescape(str) {
|
||||
return str.replace(reg, (tag) => map[tag] || tag);
|
||||
}
|
||||
|
||||
async function loadSubtitleAsVtt(option) {
|
||||
const { getExt, srtToVtt, assToVtt } = Artplayer.utils;
|
||||
async function loadSubtitleAsVtt(option, art) {
|
||||
const { getExt, srtToVtt, assToVtt } = art.constructor.utils;
|
||||
const response = await fetch(option.url);
|
||||
const buffer = await response.arrayBuffer();
|
||||
const decoder = new TextDecoder(option.encoding || 'utf-8');
|
||||
@@ -64,7 +64,7 @@ function mergeVtts(vtts, subtitles) {
|
||||
|
||||
export default function artplayerPluginMultipleSubtitles({ subtitles }) {
|
||||
return async (art) => {
|
||||
const vtts = await Promise.all(subtitles.map(loadSubtitleAsVtt));
|
||||
const vtts = await Promise.all(subtitles.map((option) => loadSubtitleAsVtt(option, art)));
|
||||
const vtt = mergeVtts(vtts, subtitles);
|
||||
const url = URL.createObjectURL(new Blob([vtt], { type: 'text/vtt' }));
|
||||
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
Reference in new issue
Block a user