0%

hexo插件-视频播放器

引用示例

npm install

1
npm install hexo-tag-dplayer --save

Usage

1
{% dplayer key=value ... %}

key 可以是

1
2
3
4
5
6
7
8
dplayer options:
'autoplay', 'loop', 'screenshot', 'hotkey', 'mutex', 'dmunlimited' : bool options, use "yes" "y" "true" "1" "on" or just without value to enable
'preload', 'theme', 'lang', 'logo', 'url', 'pic', 'thumbnails', 'vidtype', 'suburl', 'subtype', 'subbottom', 'subcolor', 'subcolor', 'id', 'api', 'token', 'addition', 'dmuser' : string arguments
'volume', 'maximum' : number arguments
container options:
'width', 'height' : string, used in container element style
other:
'code' : value of this key will be append to script tag

arguments to DPlayer options mapping:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
{
container: "you needn't set this",
autoplay: 'autoplay',
theme: 'theme',
loop: 'loop',
lang: 'lang',
screenshot: 'screenshot',
hotkey: 'hotkey',
preload: 'preload',
logo: 'logo',
volume: 'volume',
mutex: 'mutex',
video: {
url: 'url',
pic: 'pic',
thumbnails: 'thumbnails',
type: 'vidtype',
},
subtitle: {
url: 'suburl',
type: 'subtype',
fontSize: 'subsize',
bottom: 'subbottom',
color: 'subcolor',
},
danmaku: {
id: 'id',
api: 'api',
token: 'token',
maximum: 'maximum',
addition: ['addition'],
user: 'dmuser',
unlimited: 'dmunlimited',
},
icons: 'icons',
contextmenu: 'menu'
}

去 dplayer 文档查看更多信息.

例如:

1
2
{% dplayer "url=https://moeplayer.b0.upaiyun.com/dplayer/hikarunara.mp4" "addition=https://dplayer.daoapp.io/bilibili?aid=4157142" "api=https://api.prprpr.me/dplayer/" "pic=https://moeplayer.b0.upaiyun.com/dplayer/hikarunara.jpg" "id=9E2E3368B56CDBB4" "loop=yes" "theme=#FADFA3" "autoplay=false" "token=tokendemo" %}
{% dplayer 'url=some.mp4' "id=someid" "api=https://api.prprpr.me/dplayer/" "addition=/some.json" 'code=player.on("loadstart",function(){console.log("loadstart")})' "autoplay" %}

PJAX 兼容

1
2
3
4
5
6
7
8
$(document).on('pjax:start', function () {
if (window.dplayers) {
for (let i = 0; i < window.dplayers.length; i++) {
window.dplayers[i].destroy();
}
window.dplayers = [];
}
});

自定义

你可以根据自己博客的目录结构,

  • index.js 中: 定义变量 scriptDir(默认: “/assets/js/“ ) and styleDir(默认: “/assets/css/“);
  • 使用 _config.yml 配置:
1
2
3
4
5
6
7
8
# on _config.yml of hexo-site
hexo-tag-dplayer:
js_path: /path/to/your/default/path
css_path: /sth
default: #default tag argument
id: somedefid # equals to setting id=somedefid in all {%dplayer%} tags
api: https://api.prprpr.me/dplayer/
#and other options...

DPlayer 查看详情

读后有收获的话,请作者喝杯奶茶吧~