mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-31 04:31:20 -08:00
Refactor loadSubtitleAsVtt to use
art.constructor.utils
This commit is contained in:
1 parent
89b8525f2f
commit
783bf1cac3
2 files changed
+608
-599
No files matched your search
@@ -12,8 +12,8 @@ function unescape(str) {
|
|||||||
return str.replace(reg, (tag) => map[tag] || tag);
|
return str.replace(reg, (tag) => map[tag] || tag);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function loadSubtitleAsVtt(option) {
|
async function loadSubtitleAsVtt(option, art) {
|
||||||
const { getExt, srtToVtt, assToVtt } = Artplayer.utils;
|
const { getExt, srtToVtt, assToVtt } = art.constructor.utils;
|
||||||
const response = await fetch(option.url);
|
const response = await fetch(option.url);
|
||||||
const buffer = await response.arrayBuffer();
|
const buffer = await response.arrayBuffer();
|
||||||
const decoder = new TextDecoder(option.encoding || 'utf-8');
|
const decoder = new TextDecoder(option.encoding || 'utf-8');
|
||||||
@@ -64,7 +64,7 @@ function mergeVtts(vtts, subtitles) {
|
|||||||
|
|
||||||
export default function artplayerPluginMultipleSubtitles({ subtitles }) {
|
export default function artplayerPluginMultipleSubtitles({ subtitles }) {
|
||||||
return async (art) => {
|
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 vtt = mergeVtts(vtts, subtitles);
|
||||||
const url = URL.createObjectURL(new Blob([vtt], { type: 'text/vtt' }));
|
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