> For the complete documentation index, see [llms.txt](https://polyv.gitbook.io/document/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://polyv.gitbook.io/document/docs/live/js/live-player/new/function/danmu.md).

# 弹幕

## 功能介绍

POLYV播放器拥有弹幕功能，可以增加观看视频时的互动性

## 功能API

### 参数

| 参数名         | 类型      | 默认值     | 说明               |
| ----------- | ------- | ------- | ---------------- |
| danmuEnable | boolean | `false` | 是否开启弹幕功能         |
| showDanmu   | boolean | `true`  | 弹幕状态，false时一开始关闭 |
| banDanmuBtn | boolean | `false` | 为true时不显示弹幕按钮    |

参数设置示例

```javascript
var player = polyvLivePlayer({
  wrap: '#player',
  width: 800,
  height: 533,
  uid:'uid',
  vid:'vid',
  danmuEnable: true,
});
```

### 方法

| 方法名                    | 参数      | 返回值 | 说明                           |
| ---------------------- | ------- | --- | ---------------------------- |
| j2s\_addBarrageMessage | string  | /   | 弹幕支持文字和图片，图片需要用\[\[...]]包含起来 |
| setBarrageStatus       | boolean | /   | 动态显示隐藏弹幕模块                   |

方法调用示例

```javascript
const str = 'ajskd[[http://www.mywebsite.com/1.jpg]]'
const danmuData = `[{"msg":"${str}","fontSize":24,"fontColor":"0xffffff","fontMode":"roll"}]`;
player.j2s_addBarrageMessage(danmuData);

player.setBarrageStatus(false);
```

方法详解

`j2s_addBarrageMessage`

| 参数名             | 取值         | 默认值      | 说明                      | 是否必须项 |
| --------------- | ---------- | -------- | ----------------------- | ----- |
| msg             | /          | /        | 弹幕内容，图片需要用\[\[...]]包含起来 | ✔️    |
| fontSize        | 12\~       | 30       | 字体大小                    | ✔️    |
| fontColor       | 16进制颜色值    | 0x000000 | 字体颜色                    | ✔️    |
| fontMode        | roll       | roll     | 出现方式                    | ✔️    |
| fontArea        | top/bottom | /        | 出现区域                    |       |
| fontAreaPercent | /          | 25%      | 出现区域百分比                 |       |
