mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-29 02:51:20 -08:00
V5 (#509)
* update artplayer.d.ts * update variables.less * update artplayerPluginControl * build:all * update docs * update docs * update docs * Update layers.md * update index.js * update docs * update docs
This commit is contained in:
1 parent
c8c08137c4
commit
ee49a0435e
202 files changed
+5293
-3466
No files matched your search
@@ -1,222 +0,0 @@
|
||||
# 组件配置
|
||||
|
||||
这里所说的组件配置主要是指:`layers` , `controls` , `contextmenu` 这三个共用的配置:
|
||||
|
||||
| 属性 | 类型 | 描述 |
|
||||
| --------- | ------------------- | -------------------------- |
|
||||
| `disable` | `Boolean` | 是否禁用组件 |
|
||||
| `name` | `String` | 组件唯一名称,用于标记类名 |
|
||||
| `index` | `Number` | 组件索引,用于显示的优先级 |
|
||||
| `html` | `String`, `Element` | 组件的 DOM 元素 |
|
||||
| `style` | `Object` | 组件样式对象 |
|
||||
| `click` | `Function` | 组件点击事件 |
|
||||
| `mounted` | `Function` | 组件挂载后触发 |
|
||||
| `tooltip` | `String` | 组件的提示文本 |
|
||||
|
||||
:::warning 提示
|
||||
|
||||
- 当前组件只能添加,并没有销毁的功能
|
||||
- 通过 `name` 选项可以快速获取组件的 `DOM` 元素
|
||||
- 通过 `index` 选项可以控制组件出现的顺序
|
||||
|
||||
:::
|
||||
|
||||
## `layers`
|
||||
|
||||
实例化时添加一个层,例如可以添加 `logo` 或者 `广告` 等等
|
||||
|
||||
<div className="run-code">▶ Run Code</div>
|
||||
|
||||
```js{5-22}
|
||||
var img = '/assets/sample/layer.png';
|
||||
var art = new Artplayer({
|
||||
container: '.artplayer-app',
|
||||
url: '/assets/sample/video.mp4',
|
||||
layers: [
|
||||
{
|
||||
name: 'potser',
|
||||
html: `<img style="width: 100px" src="${img}">`,
|
||||
tooltip: 'Potser Tip',
|
||||
style: {
|
||||
position: 'absolute',
|
||||
top: '50px',
|
||||
right: '50px',
|
||||
},
|
||||
click: function (...args) {
|
||||
console.info('click', args);
|
||||
},
|
||||
mounted: function (...args) {
|
||||
console.info('mounted', args);
|
||||
},
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
console.info(art.layers.potser);
|
||||
```
|
||||
|
||||
也可以实例化之后添加一个层
|
||||
|
||||
<div className="run-code">▶ Run Code</div>
|
||||
|
||||
```js{7-22}
|
||||
var img = '/assets/sample/layer.png';
|
||||
var art = new Artplayer({
|
||||
container: '.artplayer-app',
|
||||
url: '/assets/sample/video.mp4',
|
||||
});
|
||||
|
||||
art.layers.add({
|
||||
name: 'potser',
|
||||
html: `<img style="width: 100px" src="${img}">`,
|
||||
tooltip: 'Potser Tip',
|
||||
style: {
|
||||
position: 'absolute',
|
||||
top: '50px',
|
||||
right: '50px',
|
||||
},
|
||||
click: function (...args) {
|
||||
console.info('click', args);
|
||||
},
|
||||
mounted: function (...args) {
|
||||
console.info('mounted', args);
|
||||
},
|
||||
});
|
||||
|
||||
console.info(art.layers.potser);
|
||||
```
|
||||
|
||||
## `controls`
|
||||
|
||||
实例化时添加一个控制器
|
||||
|
||||
:::warning controls 还有三个额外的选项
|
||||
|
||||
- `position`: `left` 和 `right` 控制控制器出现的左右位置
|
||||
- `selector`: 选择列表的对象数组
|
||||
- `onSelect`: 选择列表的元素被点击时触发的函数
|
||||
|
||||
:::
|
||||
|
||||
<div className="run-code">▶ Run Code</div>
|
||||
|
||||
```js
|
||||
var art = new Artplayer({
|
||||
container: '.artplayer-app',
|
||||
url: '/assets/sample/video.mp4',
|
||||
controls: [
|
||||
{
|
||||
name: 'your-button',
|
||||
index: 10,
|
||||
position: 'left',
|
||||
html: 'Your Button',
|
||||
tooltip: 'Your Button',
|
||||
style: {
|
||||
color: 'red',
|
||||
},
|
||||
click: function (...args) {
|
||||
console.info('click', args);
|
||||
},
|
||||
mounted: function (...args) {
|
||||
console.info('mounted', args);
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'subtitle',
|
||||
position: 'right',
|
||||
html: 'Subtitle',
|
||||
selector: [
|
||||
{
|
||||
default: true,
|
||||
html: '<span style="color:red">subtitle 01</span>',
|
||||
},
|
||||
{
|
||||
html: '<span style="color:yellow">subtitle 02</span>',
|
||||
},
|
||||
],
|
||||
onSelect: function (item, $dom) {
|
||||
console.info(item, $dom);
|
||||
return 'Your ' + item.html;
|
||||
},
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
console.info(art.controls['your-button']);
|
||||
console.info(art.controls.subtitle);
|
||||
```
|
||||
|
||||
也可以实例化之后添加一个控制器
|
||||
|
||||
```js{6-22}
|
||||
var art = new Artplayer({
|
||||
container: '.artplayer-app',
|
||||
url: '/assets/sample/video.mp4',
|
||||
});
|
||||
|
||||
art.controls.add({
|
||||
name: 'button1',
|
||||
index: 10,
|
||||
position: 'left',
|
||||
html: 'Your Button',
|
||||
tooltip: 'Your Button',
|
||||
style: {
|
||||
color: 'red',
|
||||
},
|
||||
click: function (...args) {
|
||||
console.info('click', args);
|
||||
},
|
||||
mounted: function (...args) {
|
||||
console.info('mounted', args);
|
||||
},
|
||||
});
|
||||
|
||||
console.info(art.controls.button1);
|
||||
```
|
||||
|
||||
## `contextmenu`
|
||||
|
||||
实例化时添加一个右键菜单
|
||||
|
||||
<div className="run-code">▶ Run Code</div>
|
||||
|
||||
```js{4-13}
|
||||
var art = new Artplayer({
|
||||
container: '.artplayer-app',
|
||||
url: '/assets/sample/video.mp4',
|
||||
contextmenu: [
|
||||
{
|
||||
name: 'your-menu',
|
||||
html: 'Your Menu',
|
||||
click: function (...args) {
|
||||
console.info(args);
|
||||
art.contextmenu.show = false;
|
||||
},
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
console.info(art.contextmenu['your-menu']);
|
||||
```
|
||||
|
||||
也可以实例化之后添加一个右键菜单
|
||||
|
||||
<div className="run-code">▶ Run Code</div>
|
||||
|
||||
```js{6-13}
|
||||
var art = new Artplayer({
|
||||
container: '.artplayer-app',
|
||||
url: '/assets/sample/video.mp4',
|
||||
});
|
||||
|
||||
art.contextmenu.add({
|
||||
name: 'your-menu',
|
||||
html: 'Your Menu',
|
||||
click: function (...args) {
|
||||
console.info(args);
|
||||
art.contextmenu.show = false;
|
||||
},
|
||||
});
|
||||
|
||||
console.info(art.contextmenu['your-menu']);
|
||||
```
|
||||
@@ -630,7 +630,7 @@ var art = new Artplayer({
|
||||
|
||||
:::warning `组件配置` 请参考以下地址:
|
||||
|
||||
[/start/component.html](/start/component.html)
|
||||
[/component/layers.html](/component/layers.html)
|
||||
|
||||
:::
|
||||
|
||||
@@ -683,7 +683,7 @@ var art = new Artplayer({
|
||||
|
||||
:::warning `设置面板` 请参考以下地址
|
||||
|
||||
[/start/setting.html](/start/setting.html)
|
||||
[/component/setting.html](/component/setting.html)
|
||||
|
||||
:::
|
||||
|
||||
@@ -714,7 +714,7 @@ var art = new Artplayer({
|
||||
|
||||
:::warning `组件配置` 请参考以下地址:
|
||||
|
||||
[/start/component.html](/start/component.html)- Type:
|
||||
[/component/contextmenu.html](/component/contextmenu.html)- Type:
|
||||
|
||||
:::
|
||||
|
||||
@@ -749,7 +749,7 @@ var art = new Artplayer({
|
||||
|
||||
:::warning `组件配置` 请参考以下地址:
|
||||
|
||||
[/start/component.html](/start/component.html)
|
||||
[/component/controls.html](/component/controls.html)
|
||||
|
||||
:::
|
||||
|
||||
@@ -928,13 +928,14 @@ var art = new Artplayer({
|
||||
|
||||
设置视频的字幕,支持字幕格式:`vtt`, `srt`, `ass`
|
||||
|
||||
| 属性 | 类型 | 描述 |
|
||||
| ---------- | --------- | ----------------------------------- |
|
||||
| `url` | `String` | 字幕地址 |
|
||||
| `type` | `String` | 字幕类型,可选 `vtt`, `srt`, `ass` |
|
||||
| `style` | `Object` | 字幕样式 |
|
||||
| `encoding` | `String` | 字幕编码,默认 `utf-8` |
|
||||
| `escape` | `Boolean` | 是否转义 `html` 标签,默认为 `true` |
|
||||
| 属性 | 类型 | 描述 |
|
||||
| ----------- | ---------- | ----------------------------------- |
|
||||
| `url` | `String` | 字幕地址 |
|
||||
| `type` | `String` | 字幕类型,可选 `vtt`, `srt`, `ass` |
|
||||
| `style` | `Object` | 字幕样式 |
|
||||
| `encoding` | `String` | 字幕编码,默认 `utf-8` |
|
||||
| `escape` | `Boolean` | 是否转义 `html` 标签,默认为 `true` |
|
||||
| `onVttLoad` | `Function` | 用于修改 `vtt` 文本的函数 |
|
||||
|
||||
<div className="run-code">▶ Run Code</div>
|
||||
|
||||
@@ -1212,3 +1213,28 @@ var art = new Artplayer({
|
||||
airplay: true,
|
||||
});
|
||||
```
|
||||
|
||||
## `cssVar`
|
||||
|
||||
- Type: `Object`
|
||||
- Default: `{}`
|
||||
|
||||
用于改变内置的css变量
|
||||
|
||||
<div className="run-code">▶ Run Code</div>
|
||||
|
||||
```js{4}
|
||||
var art = new Artplayer({
|
||||
container: '.artplayer-app',
|
||||
url: '/assets/sample/video.mp4',
|
||||
cssVar: {
|
||||
//
|
||||
},
|
||||
});
|
||||
```
|
||||
|
||||
:::warning cssVar 写法参考
|
||||
|
||||
[artplayer/types/cssVar.d.d.ts](https://github.com/zhw2590582/ArtPlayer/blob/master/packages/artplayer/types/cssVar.d.ts)
|
||||
|
||||
:::
|
||||
@@ -1,213 +0,0 @@
|
||||
# 设置面板
|
||||
|
||||
需先打开设置面板,播放器默认自带四个设置项:`flip`, `playbackRate`, `aspectRatio`, `subtitleOffset`
|
||||
|
||||
<div className="run-code">▶ Run Code</div>
|
||||
|
||||
```js{4}
|
||||
var art = new Artplayer({
|
||||
container: '.artplayer-app',
|
||||
url: '/assets/sample/video.mp4',
|
||||
setting: true,
|
||||
flip: true,
|
||||
playbackRate: true,
|
||||
aspectRatio: true,
|
||||
subtitleOffset: true,
|
||||
});
|
||||
```
|
||||
|
||||
## 选择列表
|
||||
|
||||
| 属性 | 类型 | 描述 |
|
||||
| ---------- | ------------------- | ------------ |
|
||||
| `html` | `String`, `Element` | 元素的 DOM |
|
||||
| `icon` | `String`, `Element` | 元素的图标 |
|
||||
| `selector` | `Array` | 元素列表 |
|
||||
| `onSelect` | `Function` | 元素点击事件 |
|
||||
| `width` | `Number` | 列表宽度 |
|
||||
| `tooltip` | `String` | 提示文本 |
|
||||
|
||||
<div className="run-code">▶ Run Code</div>
|
||||
|
||||
```js
|
||||
var art = new Artplayer({
|
||||
container: '.artplayer-app',
|
||||
url: '/assets/sample/video.mp4',
|
||||
setting: true,
|
||||
settings: [
|
||||
{
|
||||
html: 'Subtitle',
|
||||
width: 250,
|
||||
tooltip: 'Subtitle 01',
|
||||
selector: [
|
||||
{
|
||||
default: true,
|
||||
html: '<span style="color:red">Subtitle 01</span>',
|
||||
url: '/assets/sample/subtitle.srt?id=1',
|
||||
},
|
||||
{
|
||||
html: '<span style="color:yellow">Subtitle 02</span>',
|
||||
url: '/assets/sample/subtitle.srt?id=2',
|
||||
},
|
||||
],
|
||||
onSelect: function (item, $dom, event) {
|
||||
console.info(item, $dom, event);
|
||||
art.subtitle.url = item.url;
|
||||
return item.html;
|
||||
},
|
||||
},
|
||||
{
|
||||
html: 'Quality',
|
||||
width: 150,
|
||||
tooltip: '1080P',
|
||||
selector: [
|
||||
{
|
||||
default: true,
|
||||
html: '1080P',
|
||||
url: '/assets/sample/video.mp4?id=1080',
|
||||
},
|
||||
{
|
||||
html: '720P',
|
||||
url: '/assets/sample/video.mp4?id=720',
|
||||
},
|
||||
{
|
||||
html: '360P',
|
||||
url: '/assets/sample/video.mp4?id=360',
|
||||
},
|
||||
],
|
||||
onSelect: function (item, $dom, event) {
|
||||
console.info(item, $dom, event);
|
||||
art.switchQuality(item.url, item.html);
|
||||
return item.html;
|
||||
},
|
||||
},
|
||||
],
|
||||
});
|
||||
```
|
||||
|
||||
## 列表嵌套
|
||||
|
||||
<div className="run-code">▶ Run Code</div>
|
||||
|
||||
```js
|
||||
var art = new Artplayer({
|
||||
container: '.artplayer-app',
|
||||
url: '/assets/sample/video.mp4',
|
||||
setting: true,
|
||||
settings: [
|
||||
{
|
||||
html: 'Multi-level',
|
||||
selector: [
|
||||
{
|
||||
html: 'Setting 01',
|
||||
width: 150,
|
||||
selector: [
|
||||
{
|
||||
html: 'Setting 01 - 01',
|
||||
},
|
||||
{
|
||||
html: 'Setting 01 - 02',
|
||||
},
|
||||
],
|
||||
onSelect: function (item, $dom, event) {
|
||||
console.info(item, $dom, event);
|
||||
return item.html;
|
||||
},
|
||||
},
|
||||
{
|
||||
html: 'Setting 02',
|
||||
width: 150,
|
||||
selector: [
|
||||
{
|
||||
html: 'Setting 02 - 01',
|
||||
},
|
||||
{
|
||||
html: 'Setting 02 - 02',
|
||||
},
|
||||
],
|
||||
onSelect: function (item, $dom, event) {
|
||||
console.info(item, $dom, event);
|
||||
return item.html;
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
});
|
||||
```
|
||||
|
||||
## 切换按钮
|
||||
|
||||
| 属性 | 类型 | 描述 |
|
||||
| ---------- | ------------------- | --------------- |
|
||||
| `html` | `String`, `Element` | 元素的 DOM 元素 |
|
||||
| `icon` | `String`, `Element` | 元素的图标 |
|
||||
| `switch` | `Boolean` | 按钮默认状态 |
|
||||
| `onSwitch` | `Function` | 按钮切换事件 |
|
||||
| `tooltip` | `String` | 提示文本 |
|
||||
|
||||
<div className="run-code">▶ Run Code</div>
|
||||
|
||||
```js
|
||||
var art = new Artplayer({
|
||||
container: '.artplayer-app',
|
||||
url: '/assets/sample/video.mp4',
|
||||
setting: true,
|
||||
settings: [
|
||||
{
|
||||
html: 'PIP Mode',
|
||||
tooltip: 'Close',
|
||||
icon: '<img width="22" heigth="22" src="/assets/img/state.svg">',
|
||||
switch: false,
|
||||
onSwitch: function (item, $dom, event) {
|
||||
console.info(item, $dom, event);
|
||||
const nextState = !item.switch;
|
||||
art.pip = nextState;
|
||||
item.tooltip = nextState ? 'Open' : 'Close';
|
||||
return nextState;
|
||||
},
|
||||
},
|
||||
],
|
||||
});
|
||||
```
|
||||
|
||||
## 范围滑块
|
||||
|
||||
| 属性 | 类型 | 描述 |
|
||||
| ---------- | ------------------- | ---------------- |
|
||||
| `html` | `String`, `Element` | 元素的 DOM 元素 |
|
||||
| `icon` | `String`, `Element` | 元素的图标 |
|
||||
| `range` | `Array` | 默认状态数组 |
|
||||
| `onRange` | `Function` | 完成时触发的事件 |
|
||||
| `onChange` | `Function` | 变化时触发的事件 |
|
||||
| `tooltip` | `String` | 提示文本 |
|
||||
|
||||
```js
|
||||
const range = [5, 1, 10, 1];
|
||||
const value = range[0];
|
||||
const min = range[1];
|
||||
const max = range[2];
|
||||
const step = range[3];
|
||||
```
|
||||
|
||||
<div className="run-code">▶ Run Code</div>
|
||||
|
||||
```js
|
||||
var art = new Artplayer({
|
||||
container: '.artplayer-app',
|
||||
url: '/assets/sample/video.mp4',
|
||||
setting: true,
|
||||
settings: [
|
||||
{
|
||||
html: 'Slider',
|
||||
tooltip: '5x',
|
||||
icon: '<img width="22" heigth="22" src="/assets/img/state.svg">',
|
||||
range: [5, 1, 10, 1],
|
||||
onChange: function (item, $dom, event) {
|
||||
console.info(item, $dom, event);
|
||||
return item.range + 'x';
|
||||
},
|
||||
},
|
||||
],
|
||||
});
|
||||
```
|
||||
Reference in new issue
Block a user