Skip to content

Video

npm versionnpm monthly downloadsnpm sizenpm license

Multi-platform video embedding plugin, supporting Bilibili, YouTube, AcFun, and ArtPlayer.

Installation

sh
pnpm add vitepress-plugin-video
sh
npm install vitepress-plugin-video
sh
bun add vitepress-plugin-video
sh
deno add vitepress-plugin-video
sh
yarn add vitepress-plugin-video

Usage

.vitepress/config.ts
ts
import { defineConfig } from 'vitepress-tuck'
import video from 'vitepress-plugin-video'

export default defineConfig({
  plugins: [
    video({
      // All optional, default to true
      artplayer: true,
      youtube: true,
      bilibili: true,
      acfun: true,
    }),
  ],
})

Learn more about vitepress-tuck

Native Mode

.vitepress/config.ts
ts
import { defineConfig } from 'vitepress'
import { videoMarkdownPlugin } from 'vitepress-plugin-video'

export default defineConfig({
  markdown: {
    config: (md) => {
      md.use(videoMarkdownPlugin, {
        artplayer: true,
        youtube: true,
        bilibili: true,
        acfun: true,
      })
    },
  },
})
.vitepress/theme/index.ts
ts
import type { Theme } from 'vitepress'
import { enhanceAppWithVideo } from 'vitepress-plugin-video/client'
import DefaultTheme from 'vitepress/theme'

export default {
  extends: DefaultTheme,
  enhanceApp(ctx) {
    enhanceAppWithVideo(ctx)
  },
} satisfies Theme

Syntax

Bilibili

Embed Bilibili videos:

md
@[bilibili](bvid)
@[bilibili](aid cid)
@[bilibili p2 autoplay time=30](bvid)
OptionTypeDescription
p{number}-Video part number
autoplaybooleanAuto play
timenumber | stringStart time, seconds or HH:MM:SS format

YouTube

Embed YouTube videos:

md
@[youtube](video_id)
@[youtube autoplay loop start=10 end=120](video_id)
OptionTypeDescription
autoplaybooleanAuto play
loopbooleanLoop playback
startnumberStart time in seconds
endnumberEnd time in seconds

AcFun

Embed AcFun videos:

md
@[acfun](ac_id)

ArtPlayer

Use ArtPlayer to embed local or remote videos:

md
@[artPlayer](/videos/demo.mp4)
@[artPlayer muted autoplay poster="/cover.jpg" width="800px"](/videos/demo.mp4)
OptionTypeDefaultDescription
autoplaybooleanfalseAuto play
mutedbooleanfalseMuted
loopbooleanfalseLoop playback
volumenumber0.75Volume level
posterstring-Cover image URL
autoMinibooleanfalseAuto mini mode
widthstring"100%"Player width
heightstring-Player height
ratiostring-Aspect ratio, e.g. "16:9"

Supports mp4, mp3, webm, ogg, mkv, mov formats.

If your video is in mpd or dash format, you'll also need to install dashjs:

sh
pnpm add dashjs
sh
npm i dashjs
sh
bun add dashjs
sh
deno add dashjs
sh
yarn add dashjs

If your video is in m3u8 or hls format, you'll also need to install hls.js:

sh
pnpm add hls.js
sh
npm i hls.js
sh
bun add hls.js
sh
deno add hls.js
sh
yarn add hls.js

If your video is in ts or flv format, you'll also need to install mpegts.js:

sh
pnpm add mpegts.js
sh
npm i mpegts.js
sh
bun add mpegts.js
sh
deno add mpegts.js
sh
yarn add mpegts.js

Configuration

ts
interface VideoPluginOptions {
  /**
   * Enable ArtPlayer
   * @default true
   */
  artplayer?: boolean

  /**
   * Enable YouTube video embedding
   * @default true
   */
  youtube?: boolean

  /**
   * Enable Bilibili video embedding
   * @default true
   */
  bilibili?: boolean

  /**
   * Enable AcFun video embedding
   * @default true
   */
  acfun?: boolean
}

Examples

Bilibili

md
@[bilibili](BV1EZ42187Hg)

YouTube

md
@[youtube](0JJPfz5dg20)

AcFun

md
@[acfun](ac47431669)

ArtPlayer

md
@[artPlayer](https://artplayer.org/assets/sample/video.mp4)

Released under the MIT License