mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-20 20:21:20 -08:00
feat: Add parameter to append danmuku library in artplayer-plugin-danmuku
This commit is contained in:
1 parent
390be821d6
commit
2d44d602e4
8 files changed
+86
-50
No files matched your search
@@ -11,7 +11,6 @@ export default class Danmuku {
|
||||
this.$player = template.$player; // 播放器容器
|
||||
|
||||
this.art = art;
|
||||
this.danmus = []; // 原始弹幕数据
|
||||
this.queue = []; // 实际弹幕队列
|
||||
this.$refs = []; // 弹幕DOM节点池
|
||||
this.isStop = false; // 是否停止
|
||||
@@ -23,12 +22,7 @@ export default class Danmuku {
|
||||
this.option = Danmuku.option;
|
||||
|
||||
// 弹幕状态池
|
||||
this.states = {
|
||||
wait: [],
|
||||
ready: [],
|
||||
emit: [],
|
||||
stop: [],
|
||||
};
|
||||
this.states = { wait: [], ready: [], emit: [], stop: [] };
|
||||
|
||||
// 初始化配置
|
||||
this.config(option);
|
||||
@@ -265,28 +259,37 @@ export default class Danmuku {
|
||||
}
|
||||
|
||||
// 加载弹幕
|
||||
async load() {
|
||||
async load(danmuku) {
|
||||
const { errorHandle } = this.utils;
|
||||
|
||||
let danmus = [];
|
||||
const target = danmuku || this.option.danmuku;
|
||||
|
||||
try {
|
||||
if (typeof this.option.danmuku === 'function') {
|
||||
this.danmus = await this.option.danmuku();
|
||||
} else if (typeof this.option.danmuku.then === 'function') {
|
||||
this.danmus = await this.option.danmuku;
|
||||
} else if (typeof this.option.danmuku === 'string') {
|
||||
this.danmus = await bilibiliDanmuParseFromUrl(this.option.danmuku);
|
||||
} else {
|
||||
this.danmus = this.option.danmuku;
|
||||
if (typeof target === 'function') {
|
||||
danmus = await target(); // 异步函数获取
|
||||
} else if (target instanceof Promise) {
|
||||
danmus = await target; // 从 Promise 对象获取
|
||||
} else if (typeof target === 'string') {
|
||||
danmus = await bilibiliDanmuParseFromUrl(target); // 从B站xml链接解析
|
||||
} else if (Array.isArray(target)) {
|
||||
danmus = [...target]; // 直接传入数组
|
||||
}
|
||||
|
||||
errorHandle(Array.isArray(this.danmus), 'Danmuku need return an array as result');
|
||||
errorHandle(Array.isArray(danmus), 'Danmuku need return an array as result');
|
||||
|
||||
this.queue = []; // 清空实际弹幕队列
|
||||
this.$danmuku.innerText = ''; // 清空弹幕层
|
||||
// 假如没有传入弹幕参数,则清空弹幕,否则追加弹幕
|
||||
if (danmuku === undefined) {
|
||||
this.reset(); // 重置弹幕
|
||||
this.queue = []; // 清空弹幕队列
|
||||
this.states = { wait: [], ready: [], emit: [], stop: [] }; // 清空弹幕状态池
|
||||
this.$refs = []; // 清空弹幕DOM节点池
|
||||
this.$danmuku.innerText = ''; // 清空弹幕层
|
||||
}
|
||||
|
||||
// 逐个验证原始弹幕并转换为实际弹幕
|
||||
for (let index = 0; index < this.danmus.length; index++) {
|
||||
const danmu = this.danmus[index];
|
||||
// 逐个验证原始弹幕并转换到弹幕队列
|
||||
for (let index = 0; index < danmus.length; index++) {
|
||||
const danmu = danmus[index];
|
||||
await this.emit(danmu);
|
||||
}
|
||||
|
||||
|
||||
@@ -80,7 +80,7 @@ export default function heatmap(art, danmuku, option) {
|
||||
} else {
|
||||
const gap = art.duration / svg.w;
|
||||
for (let x = 0; x <= svg.w; x += options.sampling) {
|
||||
const y = danmuku.danmus.filter(
|
||||
const y = danmuku.queue.filter(
|
||||
({ time }) => time > x * gap && time <= (x + options.sampling) * gap,
|
||||
).length;
|
||||
points.push([x, y]);
|
||||
|
||||
Reference in new issue
Block a user