```js
var art = new Artplayer({
container: '.artplayer-app',
url: '/assets/sample/video.mp4',
setting: true,
plugins: [
artplayerPluginDanmuku({
// Danmuku array
danmuku: [
{
text: '111', // Danmuku text
time: 1, // Send time, in seconds
color: '#fff', // Danmuku local color
border: false, // Whether to display outline
mode: 0, // Danmuku mode: 0 for scrolling, 1 for stationary
},
{
text: '222',
time: 2,
color: 'red',
border: true,
mode: 0,
},
{
text: '333',
time: 3,
color: 'green',
border: false,
mode: 1,
},
],
}),
],
});
```
Sure, below is the translation of the provided Markdown content into English, maintaining the original Markdown formatting:
## Using Danmuku XML
▶ Run Code
```js
var art = new Artplayer({
container: '.artplayer-app',
url: '/assets/sample/video.mp4',
plugins: [
artplayerPluginDanmuku({
// Danmuku XML file, consistent with the danmuku format of the Bilibili website
danmuku: '/assets/sample/danmuku.xml',
}),
],
});
```
## Using Asynchronous Call
▶ Run Code
```js
var art = new Artplayer({
container: '.artplayer-app',
url: '/assets/sample/video.mp4',
plugins: [
artplayerPluginDanmuku({
// Use Promise to return asynchronously
danmuku: function () {
return new Promise((resolve) => {
return resolve([
{
text: '111',
time: 1,
},
{
text: '222',
time: 2,
},
{
text: '333',
time: 3,
},
]);
});
},
}),
],
});
```
## `hide/show`
Hide or show the bullet comments with the methods `hide` and `show`.
▶ Run Code
```js
var art = new Artplayer({
container: '.artplayer-app',
url: '/assets/sample/video.mp4',
plugins: [
artplayerPluginDanmuku({
danmuku: '/assets/sample/danmuku.xml',
}),
],
controls: [
{
position: 'right',
html: 'Hide Danmuku',
click: function () {
art.plugins.artplayerPluginDanmuku.hide();
},
},
{
position: 'right',
html: 'Show Danmuku',
click: function () {
art.plugins.artplayerPluginDanmuku.show();
},
},
],
});
```
## `isHide`
Judge whether the current barrage is hidden or displayed with the `isHide` property.
▶ Run Code
```js
var art = new Artplayer({
container: '.artplayer-app',
url: '/assets/sample/video.mp4',
plugins: [
artplayerPluginDanmuku({
danmuku: '/assets/sample/danmuku.xml',
}),
],
controls: [
{
position: 'right',
html: 'Hide Barrage',
click: function (_, event) {
if (art.plugins.artplayerPluginDanmuku.isHide) {
art.plugins.artplayerPluginDanmuku.show();
event.target.innerText = 'Hide Barrage';
} else {
art.plugins.artplayerPluginDanmuku.hide();
event.target.innerText = 'Show Barrage';
}
},
},
],
});
```
## `emit`
Send a real-time danmaku message through the `emit` method
▶ Run Code
```js
var art = new Artplayer({
container: '.artplayer-app',
url: '/assets/sample/video.mp4',
plugins: [
artplayerPluginDanmuku({
danmuku: '/assets/sample/danmuku.xml',
}),
],
controls: [
{
position: 'right',
html: 'Send Danmaku',
click: function () {
var text = prompt('Please enter the danmaku text', 'Danmaku test text');
if (!text || !text.trim()) return;
var color = '#' + Math.floor(Math.random() * 0xffffff).toString(16);
art.plugins.artplayerPluginDanmuku.emit({
text: text,
color: color,
border: true,
});
},
},
],
});
```
## `config`
Change the barrage configuration in real-time with the `config` method, supported attributes include:
- `danmuku`
- `speed`
- `opacity`
- `fontSize`
- `color`
- `mode`
- `margin`
- `antiOverlap`
- `synchronousPlayback`
- `filter`
- `lockTime`
- `beforeEmit`
▶ Run Code
```js
var art = new Artplayer({
container: '.artplayer-app',
url: '/assets/sample/video.mp4',
plugins: [
artplayerPluginDanmuku({
danmuku: '/assets/sample/danmuku.xml',
}),
],
controls: [
{
position: 'right',
html: 'Danmaku size:',
style: {
display: 'flex',
alignItems: 'center',
},
mounted: function ($setting) {
const $range = $setting.querySelector('input[type=range]');
$range.addEventListener('change', () => {
art.plugins.artplayerPluginDanmuku.config({
fontSize: Number($range.value),
});
});
},
},
],
});
```
## `load`
The load method can be used to reload the danmu data source or switch to new danmu.
▶ Run Code
```js
var art = new Artplayer({
container: '.artplayer-app',
url: '/assets/sample/video.mp4',
plugins: [
artplayerPluginDanmuku({
danmuku: '/assets/sample/danmuku.xml',
}),
],
controls: [
{
position: 'right',
html: 'Reload Danmu',
click: function () {
art.plugins.artplayerPluginDanmuku.load();
},
},
{
position: 'right',
html: 'Switch Danmu',
click: function () {
art.plugins.artplayerPluginDanmuku.config({
danmuku: '/assets/sample/danmuku-v2.xml',
});
art.plugins.artplayerPluginDanmuku.load();
},
},
],
});
```
## `reset`
Used to clear the current displayed barrages
▶ Run Code
```js
var art = new Artplayer({
container: '.artplayer-app',
url: '/assets/sample/video.mp4',
setting: true,
plugins: [
artplayerPluginDanmuku({
danmuku: '/assets/sample/danmuku.xml',
}),
],
});
art.on('resize', () => {
art.plugins.artplayerPluginDanmuku.reset();
});
```
## `option`
Used to get the current barrage configuration
▶ Run Code
▶ Run Code
```js
var art = new Artplayer({
container: '.artplayer-app',
url: '/assets/sample/video.mp4',
setting: true,
plugins: [
artplayerPluginDanmuku({
danmuku: '/assets/sample/danmuku.xml',
}),
],
});
art.on('ready', () => {
console.info(art.plugins.artplayerPluginDanmuku.option);
});
```
## 事件
```js
var art = new Artplayer({
container: '.artplayer-app',
url: '/assets/sample/video.mp4',
setting: true,
plugins: [
artplayerPluginDanmuku({
danmuku: '/assets/sample/danmuku.xml',
}),
],
});
art.on('artplayerPluginDanmuku:emit', (danmu) => {
console.info('新增弹幕', danmu);
});
art.on('artplayerPluginDanmuku:loaded', (danmus) => {
console.info('加载弹幕', danmus.length);
});
art.on('artplayerPluginDanmuku:error', (error) => {
console.info('加载错误', error);
});
art.on('artplayerPluginDanmuku:config', (option) => {
console.info('配置变化', option);
});
art.on('artplayerPluginDanmuku:stop', () => {
console.info('弹幕停止');
});
art.on('artplayerPluginDanmuku:start', () => {
console.info('弹幕开始');
});
art.on('artplayerPluginDanmuku:hide', () => {
console.info('弹幕隐藏');
});
art.on('artplayerPluginDanmuku:show', () => {
console.info('弹幕显示');
});
art.on('artplayerPluginDanmuku:destroy', () => {
console.info('弹幕销毁');
});
```
Here is the translation of the VitePress extended Markdown syntax into English:
```markdown
# Welcome to VitePress
## Project setup
```bash
yarn
yarn docs:dev
```
## Build
To build the documentation site, run the following command:
```bash
yarn docs:build
```
## Deployment
To deploy the documentation site, you can use any static site hosting services.
```