Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
117 changes: 27 additions & 90 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,103 +1,40 @@
<br>
<p align="center">
<a href="https://sli.dev" target="_blank">
<img src="https://sli.dev/logo-title.png" alt="Slidev" height="250" width="250"/>
</a>
</p>

<p align="center">
Presentation <b>slide</b>s for <b>dev</b>elopers 🧑‍💻👩‍💻👨‍💻
</p>

<p align="center">
<a href="https://www.npmjs.com/package/@slidev/cli" target="__blank"><img src="https://img.shields.io/npm/v/@slidev/cli?color=2B90B6&label=" alt="NPM version"></a>
<a href="https://www.npmjs.com/package/@slidev/cli" target="__blank"><img alt="NPM Downloads" src="https://img.shields.io/npm/dm/@slidev/cli?color=349dbe&label="></a>
<a href="https://sli.dev/" target="__blank"><img src="https://img.shields.io/static/v1?label=&message=docs%20%26%20demos&color=45b8cd" alt="Docs & Demos"></a>
<a href="https://sli.dev/resources/theme-gallery" target="__blank"><img src="https://img.shields.io/static/v1?label=&message=themes&color=4ec5d4" alt="Themes"></a>
<br>
<a href="https://github.com/slidevjs/slidev" target="__blank"><img alt="GitHub stars" src="https://img.shields.io/github/stars/slidevjs/slidev?style=social"></a>
</p>

<p align="center">
<a href="https://twitter.com/antfu7/status/1389604687502995457">Video Preview</a> | <a href="https://sli.dev">Documentation</a>
</p>

<div align="center">
<table>
<tbody>
<td align="center">
<img width="2000" height="0" alt="" aria-hiden><br>
<sub>Made possible by my <a href="https://github.com/sponsors/antfu">Sponsor Program 💖</a></sub><br>
<img width="2000" height="0" alt="" aria-hiden>
</td>
</tbody>
</table>
</div>

## Features

- 📝 [**Markdown-based**](https://sli.dev/guide/syntax) - focus on content and use your favorite editor
- 🧑‍💻 [**Developer Friendly**](https://sli.dev/guide/syntax#code-blocks) - built-in code highlighting, live coding, etc.
- 🎨 [**Themable**](https://sli.dev/resources/theme-gallery) - theme can be shared and used with npm packages
- 🌈 [**Stylish**](https://sli.dev/guide/syntax#embedded-styles) - on-demand utilities via [UnoCSS](https://github.com/unocss/unocss).
- 🤹 [**Interactive**](https://sli.dev/custom/directory-structure#components) - embedding Vue components seamlessly
- 🎙 [**Presenter Mode**](https://sli.dev/guide/ui#presenter-mode) - use another window, or even your phone to control your slides
- 🎨 [**Drawing**](https://sli.dev/features/drawing) - draw and annotate on your slides
- 🧮 [**LaTeX**](https://sli.dev/features/latex) - built-in LaTeX math equations support
- 📰 [**Diagrams**](https://sli.dev/guide/syntax#diagrams) - creates diagrams using textual descriptions with [Mermaid](https://mermaid.js.org/)
- 🌟 [**Icons**](https://sli.dev/features/icons) - access to icons from any icon set directly
- 💻 [**Editor**](https://sli.dev/guide/index#editor) - integrated editor, or the [VSCode extension](https://sli.dev/features/vscode-extension)
- 🎥 [**Recording**](https://sli.dev/features/recording) - built-in recording and camera view
- 📤 [**Portable**](https://sli.dev/guide/exporting) - export into PDF, PNGs, or PPTX
- ⚡️ [**Fast**](https://vitejs.dev) - instant reloading powered by [Vite](https://vitejs.dev)
- 🛠 [**Hackable**](https://sli.dev/custom/) - using Vite plugins, Vue components, or any npm packages

## Getting Started

### Try it Online ⚡️

[sli.dev/new](https://sli.dev/new)

[![](https://developer.stackblitz.com/img/open_in_stackblitz.svg)](https://sli.dev/new)

### Init Project Locally

Install [Node.js >=18](https://nodejs.org/) and run the following command:
# 🎬 SlidevVideo Playback Demo
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this file has been changed?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Anthony, thanks for the feedback!
I thought I was only editing my fork, so I put the demo into the README for quick testing.
Now I understand it should go into the docs and in English.

I’ll move the content into the docs and update the PR. Thanks for pointing it out!


A simple demo showcasing **multi-step controlled video playback** using `pause` prop.

透過 `pause` 參數控制影片分段播放,支援數值與 `'end'`,可用於教學投影片互動控制。

---

## 🚀 How to Run

```bash
npm init slidev
pnpm install
pnpm dev
```

Documentation:
**[English](https://sli.dev)** | [中文文档](https://cn.sli.dev) | [Français](https://fr.sli.dev) | [Español](https://es.sli.dev) | [Русский](https://ru.sli.dev) | [Português-BR](https://br.sli.dev)
Then open [http://localhost:3030](http://localhost:3030)

---

Discord: [chat.sli.dev](https://chat.sli.dev)
## 🌐 Slide Demos | 投影片展示

For a full example, you can check the [demo](https://github.com/slidevjs/slidev/blob/main/demo) folder, which is also the source file for [my previous talk](https://antfu.me/posts/composable-vue-vueday-2021).
- 👉 [Home Page](/dev.md)

## Tech Stack
---

- [Vite](https://vitejs.dev) - An extremely fast frontend tooling
- [Vue 3](https://v3.vuejs.org/) powered [Markdown](https://daringfireball.net/projects/markdown/syntax) - Focus on the content while having the power of HTML and Vue components whenever needed
- [UnoCSS](https://github.com/unocss/unocss) - On-demand utility-first CSS engine, style your slides at ease
- [Shiki](https://github.com/shikijs/shiki), [Monaco Editor](https://github.com/Microsoft/monaco-editor) - First-class code snippets support with live coding capability
- [RecordRTC](https://recordrtc.org) - Built-in recording and camera view
- [VueUse](https://vueuse.org) family - [`@vueuse/core`](https://github.com/vueuse/vueuse), [`@vueuse/motion`](https://github.com/vueuse/motion), etc.
- [Iconify](https://iconify.design/) - Icon sets collection.
- [Drauu](https://github.com/antfu/drauu) - Drawing and annotations support
- [KaTeX](https://katex.org/) - LaTeX math rendering.
- [Mermaid](https://mermaid-js.github.io/mermaid) - Textual Diagrams.
## 💡 Example

## Sponsors
```vue
<SlidevVideo :pause="[3.5, 2.5, 3]" controls>
<source src="https://www.w3schools.com/html/mov_bbb.mp4" />
</SlidevVideo>
```

This project is made possible by all the sponsors supporting my work:
Will play **3.5s**, then pause, then **2.5s**, then pause, then **3s**, then pause, then end.

<p align="center">
<a href="https://github.com/sponsors/antfu">
<img src='https://cdn.jsdelivr.net/gh/antfu/static/sponsors.svg' alt="Logos from Sponsors" />
</a>
</p>
---

## License
## 🧩 Credit

MIT License © 2021 [Anthony Fu](https://github.com/antfu)
Based on [`Slidev`](https://github.com/slidevjs/slidev), with custom `SlidevVideo` component.
88 changes: 88 additions & 0 deletions dev.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
# 🎬 SlidevVideo Demo

> A demo for multi-step controlled playback using `pause=[1, 2, 3, 'end']`
> 使用 `pause=[1, 2, 3, 'end']` 控制多段播放的展示
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you update the docs instead? And use English, please. Thanks

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it, I’ll move the demo into the docs in English and update the PR soon.


<br>
<br>
<br>

### 🌐 Choose Language | 選擇語言

<Link to="2">English</Link>
<br>
<Link to="6">中文</Link>

---

# SlidevVideo 1.0 Test: Pause with Decimal Durations

This slide demonstrates the new `pause` feature in `SlidevVideo`:

- ✅ Supports multiple controlled playback segments
- ✅ Accepts decimal values for pause durations (e.g., `3.5` seconds)
- ✅ `'end'` is optional — without it, the last segment will stop naturally

---

## Playback Test Example

<SlidevVideo :pause="[3.5, 2.5, 3]" controls>
<source src="https://www.w3schools.com/html/mov_bbb.mp4" type="video/mp4" />
</SlidevVideo>

---

### ⏱️ Expected Playback Flow

1. First click: plays 3.5 seconds, then auto-pauses
2. Second click: plays 2.5 seconds, then auto-pauses
3. Third click: plays 3 seconds, then auto-pauses
4. Fourth click: continues playing until the video ends

---

### Notes

- `'end'` is optional — if omitted, the last segment just ends playback naturally
- To force a final uninterrupted play-to-end segment, append `'end'` manually:
```html
<SlidevVideo :pause="[3.5, 2.5, 3, 'end']"></SlidevVideo>
```

---

# 測試 SlidevVideo 1.0:Pause 支援小數點時間

這頁展示了 `SlidevVideo` 新增的 `pause` 支援:

- ✅ 多段播放控制:每點一次播放指定秒數
- ✅ 支援小數點秒數(例如 `3.5` 秒)
- ✅ 可選擇是否加入 `'end'`,若未加則播放到最後自動停止

---

## 播放測試範例

<SlidevVideo :pause="[3.5, 2.5, 3]" controls>
<source src="https://www.w3schools.com/html/mov_bbb.mp4" type="video/mp4" />
</SlidevVideo>

---

### ⏱️ 播放節奏預期

1. 點第一下:播放 3.5 秒後自動暫停
2. 點第二下:播放 2.5 秒後自動暫停
3. 點第三下:播放 3 秒後自動暫停
4. 第四下:會繼續播放到結尾(或結束整段)

---

### 備註

- 可以不必加 `'end'`,預設最後一段播放完就不會卡住
- 若要強制到最後自動播放到結尾,可明確加 `'end'`:
```html
<SlidevVideo :pause="[3.5, 2.5, 3, 'end']"></SlidevVideo>
```
137 changes: 87 additions & 50 deletions packages/client/builtin/SlidevVideo.vue
Original file line number Diff line number Diff line change
@@ -1,74 +1,111 @@
<script setup lang="ts">
import { and } from '@vueuse/math'
import { computed, onMounted, ref, watch } from 'vue'
import { useNav } from '../composables/useNav'
import { useSlideContext } from '../context'
import { resolvedClickMap } from '../modules/v-click'
import videojs from 'video.js'
import { computed, onBeforeUnmount, onMounted, ref } from 'vue'
import 'video.js/dist/video-js.css'

const props = defineProps<{
autoplay?: boolean | 'once'
autoreset?: 'slide' | 'click'
pause?: (number | 'end')[]
poster?: string
printPoster?: string
timestamp?: string | number
printTimestamp?: string | number | 'last'
controls?: boolean
}>()

const printPoster = computed(() => props.printPoster ?? props.poster)
const printTimestamp = computed(() => props.printTimestamp ?? props.timestamp ?? 0)
const videoRef = ref()
const player = ref<ReturnType<typeof videojs> | null>(null)
const currentInterval = ref<any>(null)

const { $slidev, $renderContext, $route } = useSlideContext()
const { isPrintMode } = useNav()
const rawPause = props.pause ?? []
const pauseTimestamps = computed(() => {
const out: (number | 'end')[] = [0]
for (const segment of rawPause) {
const last = out[out.length - 1]
if (segment === 'end') {
out.push('end')
}
else {
const lastNum = typeof last === 'number' ? last : 0
out.push(lastNum + segment)
}
}
return out
})

const noPlay = computed(() => isPrintMode.value || !['slide', 'presenter'].includes($renderContext.value))
const pauseIndex = ref(1)
const isPlaying = ref(false)

const video = ref<HTMLMediaElement>()
const played = ref(false)
function playNextSegment() {
const from = pauseTimestamps.value[pauseIndex.value - 1]
const to = pauseTimestamps.value[pauseIndex.value]

onMounted(() => {
if (noPlay.value)
if (!player.value || from == null || to == null)
return

const timestamp = +(props.timestamp ?? 0)
video.value!.currentTime = timestamp
if (typeof from === 'number') {
player.value.currentTime(from)
}

const matchRoute = computed(() => !!$route && $route.no === $slidev?.nav.currentSlideNo)
const matchClick = computed(() => !!video.value && (resolvedClickMap.get(video.value)?.isShown?.value ?? true))
const matchRouteAndClick = and(matchRoute, matchClick)
try {
isPlaying.value = true
player.value.play()
}
catch {
isPlaying.value = false
return
}

watch(matchRouteAndClick, () => {
if (matchRouteAndClick.value) {
if (props.autoplay === true || (props.autoplay === 'once' && !played.value))
video.value!.play()
}
else {
video.value!.pause()
if (props.autoreset === 'click' || (props.autoreset === 'slide' && !matchRoute.value))
video.value!.currentTime = timestamp
if (to === 'end') {
pauseIndex.value++
return
}

if (currentInterval.value)
clearInterval(currentInterval.value)

currentInterval.value = setInterval(() => {
if (!player.value)
return
if (player.value.currentTime() >= to) {
player.value.pause()
clearInterval(currentInterval.value)
isPlaying.value = false
pauseIndex.value++
}
}, { immediate: true })
}, 100)
}

onMounted(() => {
player.value = videojs(videoRef.value, {
controls: props.controls !== false,
autoplay: false,
preload: 'auto',
poster: props.poster,
})

player.value.ready(() => {
player.value.controls(true)
player.value.trigger('resize')
player.value.pause()
player.value.currentTime(0)

player.value.on('play', () => {
if (!isPlaying.value) {
playNextSegment()
}
else {
player.value?.pause()
}
})
})
})

function onLoadedMetadata(ev: Event) {
// The video may be loaded before component mounted
const element = ev.target as HTMLMediaElement
if (noPlay.value && (!printPoster.value || props.printTimestamp)) {
element.currentTime = printTimestamp.value === 'last'
? element.duration
: +printTimestamp.value
}
}
onBeforeUnmount(() => {
if (currentInterval.value)
clearInterval(currentInterval.value)
player.value?.dispose()
})
</script>

<template>
<video
ref="video"
:poster="noPlay ? printPoster : props.poster"
:controls="!noPlay && props.controls"
@play="played = true"
@loadedmetadata="onLoadedMetadata"
>
<video ref="videoRef" class="video-js vjs-default-skin" playsinline>
<slot />
</video>
</template>