mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-16 17:46:17 -08:00
175 lines
4.6 KiB
Markdown
175 lines
4.6 KiB
Markdown
# Controller
|
|
|
|
## Configuration
|
|
|
|
| Property | Type | Description |
|
|
| ---------- | ------------------- | ------------------------------------------ |
|
|
| `disable` | `Boolean` | Whether to disable the component |
|
|
| `name` | `String` | The unique name of the component for class identification |
|
|
| `index` | `Number` | The index of the component, used for display priority |
|
|
| `html` | `String`, `Element` | The component's DOM element |
|
|
| `style` | `Object` | The style object for the component |
|
|
| `click` | `Function` | Component click event |
|
|
| `mounted` | `Function` | Triggered after the component is mounted |
|
|
| `tooltip` | `String` | Tooltip text for the component |
|
|
| `position` | `String` | `left` and `right` control the position of the controller |
|
|
| `selector` | `Array` | An array of objects for the selection list |
|
|
| `onSelect` | `Function` | Function triggered when an item from the selection list is clicked |
|
|
|
|
## Creation
|
|
|
|
<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;
|
|
},
|
|
},
|
|
],
|
|
});
|
|
|
|
// Get the Element of control by name
|
|
console.info(art.controls['your-button']);
|
|
console.info(art.controls['subtitle']);
|
|
```
|
|
## Adding
|
|
|
|
<div className="run-code">▶ Run Code</div>
|
|
|
|
```js{6-21}
|
|
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);
|
|
},
|
|
});
|
|
|
|
// Get the Element of control by name
|
|
console.info(art.controls['button1']);
|
|
```
|
|
## Delete
|
|
|
|
<div className="run-code">▶ Run Code</div>
|
|
|
|
```js{21}
|
|
var art = new Artplayer({
|
|
container: '.artplayer-app',
|
|
url: '/assets/sample/video.mp4',
|
|
controls: [
|
|
{
|
|
name: 'button1',
|
|
index: 10,
|
|
position: 'right',
|
|
html: 'Your Button',
|
|
tooltip: 'Your Button',
|
|
style: {
|
|
color: 'red',
|
|
},
|
|
}
|
|
]
|
|
});
|
|
|
|
art.on('ready', () => {
|
|
setTimeout(() => {
|
|
// Delete the control by name
|
|
art.controls.remove('button1');
|
|
}, 3000);
|
|
});
|
|
```
|
|
## Update
|
|
|
|
<div className="run-code">▶ Run Code</div>
|
|
|
|
```js{26-40}
|
|
var art = new Artplayer({
|
|
container: '.artplayer-app',
|
|
url: '/assets/sample/video.mp4',
|
|
controls: [
|
|
{
|
|
name: 'button1',
|
|
index: 10,
|
|
position: 'right',
|
|
html: 'Subtitle',
|
|
selector: [
|
|
{
|
|
default: true,
|
|
html: 'subtitle 01',
|
|
},
|
|
{
|
|
html: 'subtitle 02',
|
|
},
|
|
],
|
|
}
|
|
]
|
|
});
|
|
|
|
art.on('ready', () => {
|
|
setTimeout(() => {
|
|
// Update the control by name
|
|
art.controls.update({
|
|
name: 'button1',
|
|
index: 10,
|
|
position: 'right',
|
|
html: 'New Subtitle',
|
|
selector: [
|
|
{
|
|
default: true,
|
|
html: 'new subtitle 01',
|
|
},
|
|
{
|
|
html: 'new subtitle 02',
|
|
},
|
|
],
|
|
});
|
|
}, 3000);
|
|
});
|
|
``` |