New:Introducing Socket Scanning for VS Code Marketplace Extensions.Learn more →
Get Started

bili-player

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bili-player

一个模拟B站播放器的视频组件

npmnpm
Version
0.0.2
Version published
Weekly downloads
2
-75%
Maintainers
1
Weekly downloads
 
Created
Source

效果图

快速开始

npm i bili-player

<template>
  <bili-player
    ref="biliPlayerRef"
    style="width: 900px; height: 550px"
    v-bind="playerProps"
  />
</template>

<script setup lang="ts">
import "bili-player/style.css";
import { onMounted, ref } from "vue";
import {
  BiliPlayer,
  type BiliDanmakuItem,
  type BiliPlayerProps,
} from "bili-player";

const biliPlayerRef = ref<InstanceType<typeof BiliPlayer>>();
const playerProps: BiliPlayerProps = {
  video: {
    poster: "https://i.loli.net/2019/06/06/5cf8c5d9c57b510947.png",
    url: "https://api.dogecloud.com/player/get.mp4?vcode=5ac682e6f8231991&userId=17&ext=.mp4",
    autoplay: true,
  },
  danmaku: {
    sendCallback: async (data: BiliDanmakuItem) => {
      // request send
    },
    filter: (data: BiliDanmakuItem) => {
      // 屏蔽弹幕 '前方高能'
      return !data.content.includes("前方高能");
    },
  },
};

const danmaItems: BiliDanmakuItem[] = [
  { content: "君だよ 君なんだよ  教えてくれた", time: 1, type: 0, color: "white" },
  { content: "Goose house炒鸡棒!!!  银之匙种草他们组合", time: 1.2, type: 2, color: "red" },
  { content: "朱军,拔剑吧", time: 1.6, type: 0, color: "green" },
  { content: "听了好多次", time: 6.6, type: 1, color: "white" },
  { content: "带耳机听,贝斯的声音会更加带感!", time: 4.3, type: 0, color: "black" },
  { content: "胖子哥声音太美", time: 3.2, type: 1, color: "white" },
  { content: "练习室版本吧。就像live和专辑。", time: 3.6, type: 0, color: "white" },
  { content: "左下角的妹子唱副歌的,很难的", time: 2.2, type: 1, color: "blue" },
];
onMounted(() => {
  const danmaControl = biliPlayerRef.value?.getDanmaControls();
  danmaControl?.setDanmakus(danmaItems);
});
</script>

参数说明

名称类型描述默认值
hotkeyboolean开启快捷键true
videoBiliVideoProps视频参数
video.urlstring视频路径
video.posterstring封面路径
video.trackstring字幕路径
video.loopboolean是否循环播放false
video.autoplayboolean是否自动播放true
video.volumenumber默认音量大小0.5
video.ratenumber播放速率1
danmakuBiliDanmakuProps
danmaku.showboolean展示弹幕true
danmaku.fontRationumber字体大小比率,0.5 - 1.51
danmaku.fontBoldboolean字体是否加粗false
danmaku.speednumber速度 0.5 - 2.01
danmaku.opacitynumber不透明度 0 - 11
danmaku.displaySizenumber显示区域 0.25 - 11
danmaku.visible.moveboolean滚动弹幕显示true
danmaku.visible.topboolean顶部弹幕显示true
danmaku.visible.bottomboolean底部弹幕显示true
danmaku.visible.colorboolean彩色弹幕显示true
danmaku.sendCallback(dan: BiliDanmakuItem) => Promise | any发送弹幕回调,若不发送,抛出错误即可
danmaku.filter(dan: BiliDanmakuItem) => boolean | Promise弹幕显示过滤

API说明

名称描述
getVideoControls获取视频控制器,返回基于vueuse的useMediaControls的返回值
getDanmaControls获取弹幕控制器

Keywords

bili

FAQs

Package last updated on 24 Feb 2024

Related posts