mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-21 04:31:20 -08:00
chore: Refactor artplayer-plugin-chapter to sort chapters before processing
This commit is contained in:
1 parent
5edf5af672
commit
d8ff61acf7
3 files changed
+15
-3
No files matched your search
@@ -181,10 +181,11 @@ function artplayerPluginChapter(option = {}) {
|
||||
function update(chapters = []) {
|
||||
if (!chapters.length) return;
|
||||
if (!art.duration) return;
|
||||
$control.innerText = "";
|
||||
chapters = chapters.sort((a, b)=>a.start - b.start);
|
||||
for(let i = 0; i < chapters.length; i++){
|
||||
const chapter = chapters[i];
|
||||
const nextChapter = chapters[i + 1];
|
||||
if (typeof chapter.start !== "number" || typeof chapter.end !== "number" || typeof chapter.title !== "string") throw new Error("Illegal chapter data type");
|
||||
if (chapter.start < 0 || chapter.end > art.duration || chapter.start >= chapter.end) throw new Error("Illegal chapter time point");
|
||||
if (nextChapter && chapter.end > nextChapter.start) throw new Error("Illegal chapter time point");
|
||||
}
|
||||
@@ -203,6 +204,7 @@ function artplayerPluginChapter(option = {}) {
|
||||
end: chapters[i + 1].start,
|
||||
title: ""
|
||||
});
|
||||
$control.innerText = "";
|
||||
$chapters = chapters.map((chapter)=>{
|
||||
const $chapter = append($control, html);
|
||||
const start = clamp(chapter.start, 0, art.duration);
|
||||
|
||||
Reference in new issue
Block a user