Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
feat: add danmuku support
Browse files Browse the repository at this point in the history
  • Loading branch information
123485k committed Jun 11, 2022
1 parent af3e2c8 commit 557102f
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 1 deletion.
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -32,6 +32,7 @@
"@monaco-editor/react": "^4.4.4",
"@xhofe/react-viewer": "^3.2.3",
"artplayer": "^4.4.3",
"artplayer-plugin-danmuku": "^4.4.6",
"axios": "^0.26.0",
"flv.js": "^1.6.2",
"framer-motion": "^5.5.6",
Expand Down
35 changes: 34 additions & 1 deletion src/pages/list/preview/video.tsx
Expand Up @@ -23,7 +23,7 @@ import { BsCardList } from "react-icons/bs";
import useFileUrl from "../../../hooks/useFileUrl";
import { isMobile, userAgent } from "../../../utils/compatibility";
import Hls from "hls.js";

import artplayerPluginDanmuku from "artplayer-plugin-danmuku"
export const type = 3;
export const exts = ["m3u8"];
// const DirectDrivers = ["Native", "GoogleDrive"];
Expand Down Expand Up @@ -141,6 +141,39 @@ const Video = ({ file }: FileProps) => {
},
};
}
const danmu = lastFiles.find((f) => {
const fName = f.name;
if (!fName.startsWith(filename)) {
return false;
}
for (const ext of ["xml"]) {
if (fName.endsWith(ext)) {
return true;
}
}
return false;
});
if (danmu) {
options.plugins = [
artplayerPluginDanmuku({
danmuku: fileUrl(danmu),
speed: 5, // 弹幕持续时间,单位秒,范围在[1 ~ 10]
opacity: 1, // 弹幕透明度,范围在[0 ~ 1]
fontSize: 25, // 字体大小,支持数字和百分比
color: '#FFFFFF', // 默认字体颜色
mode: 0, // 默认模式,0-滚动,1-静止
margin: [0, '0%'], // 弹幕上下边距,支持数字和百分比
antiOverlap: false, // 是否防重叠
useWorker: true, // 是否使用 web worker
synchronousPlayback: false, // 是否同步到播放速度
lockTime: 5, // 输入框锁定时间,单位秒,范围在[1 ~ 60]
maxLength: 100, // 输入框最大可输入的字数,范围在[0 ~ 500]
minWidth: 200, // 输入框最小宽度,范围在[0 ~ 500],填 0 则为无限制
maxWidth: 400, // 输入框最大宽度,范围在[0 ~ Infinity],填 0 则为 100% 宽度
theme: 'dark', // 输入框自定义挂载时的主题色,默认为 dark,可以选填亮色 light
})
]
}
art = new Artplayer(options);
art.on("video:ended", () => {
const index = videoFiles.findIndex((f) => f.name === file.name);
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Expand Up @@ -1214,6 +1214,11 @@ aria-hidden@^1.1.1:
dependencies:
tslib "^1.0.0"

artplayer-plugin-danmuku@^4.4.6:
version "4.4.6"
resolved "https://registry.npmmirror.com/artplayer-plugin-danmuku/-/artplayer-plugin-danmuku-4.4.6.tgz#3f01a60f71992d8779b3bb028e93929da7a4dcd7"
integrity sha512-Q5LWMwzdtFF/SmRQzjD8itMG6v/VghOmHiUe0WM3mnuKRZCS6H4wWsE3dCp95UTPY9GxaRmq0t5T2miVc6/1oQ==

artplayer@^4.4.3:
version "4.4.3"
resolved "https://registry.yarnpkg.com/artplayer/-/artplayer-4.4.3.tgz#9387d30ecac836f4918d6c083a6cb66d97932ed3"
Expand Down

0 comments on commit 557102f

Please sign in to comment.