Files
MujicaUI/docs/components/345-video-player.md
T
ZacharyZhang-NYandClaude Opus 5.5 bcce34cda1 Upgrade MyGo to v0.5.5
MyGo v0.5.5 returns ui.Element as a checked value handle instead of a
pointer. Migrated with `mygo migrate-ui`, then fixed what the codemod
leaves to review:

- Element nil checks become .Valid(); absent elements are ui.Element{}.
- Input handlers and paint callbacks run outside the build pass, where
  elements expire and Context methods are inert: read IsDisabled into a
  local during the build, keep a ui.Handle for Focus, use c.Services()
  for clipboard access, create ui.Local state during the build.
- Add core.AutoFocus: v0.5.5 records an overlay's opener after its
  content builds, so same-frame autofocus lost focus restore on close.
  It focuses one frame later; cascader rows defer their focus likewise.
- core.OverlayLayer identifies build passes by the root element, not
  c.Now(), which repeats across passes and under the Tester clock.
- Context menus survive the opening press counted as PressedOutside;
  split button tooltip no longer reorders its open menu; disabled
  menubar rows pass presses to the panel; Form defers blur-started
  async checks so the growing message no longer moves Submit away
  from the release; Combobox drops its disabled copy now that MyGo
  blocks typing under a disabled wrapper (canary flipped to a guard).
- The Tester clock is virtual: tests use Advance/Now instead of
  time.Sleep/time.Now and read element state inside the view. The web
  mirror advances the clock to wall time before each frame and input.
- AGENTS.md and docs describe the value Element API and the new pin.

Snapshot goldens are darwin-only and were not re-verified here.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-17 01:37:54 -04:00

60 lines
2.0 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 345 VideoPlayer 视频播放器
## 用途
播放器外壳:画面由调用方提供,组件绘制状态并通过回调报告播放、暂停、跳转、倍速、字幕、全屏和画中画。
## 最小示例
```go
st := media.VideoState{Duration: 4 * time.Minute, Rate: 1}
view := func(c *ui.Context) {
core.Use(c, core.Settings{})
media.VideoPlayer(c, st, media.VideoPlayerOptions{
OnPlay: func() { st.Playing = true }, // start your decoder
OnPause: func() { st.Playing = false }, // pause it
OnSeek: func(d time.Duration) { st.Position = d },
OnRate: func(r float64) { st.Rate = r },
})
}
ui.Render(view, 400, 300, 1)
```
## 参数
`func VideoPlayer(c *ui.Context, st VideoState, opts VideoPlayerOptions) ui.Element`
`VideoState`:`Frame`(当前画面,nil 显示“暂无视频”)、`Position`、`Duration`、`Buffered`、`Playing`、`Rate`、`Subtitle`、`SubtitlesOn`、`Fullscreen`、`PiP`。
| 字段 | 类型 | 默认值 | 含义 |
| --- | --- | --- | --- |
| `OnPlay / OnPause / OnSeek` | `func` | 必填 | 播放、暂停、跳转。 |
| `OnRate` | `func(float64)` | nil | 倍速;nil 时不显示倍速选择。 |
| `OnSubtitles / OnFullscreen / OnPiP` | `func(bool)` | nil | 开关回调;nil 时隐藏对应按钮。 |
| `Disabled` | `bool` | false | 禁用全部控件。 |
| `Label` | `string` | "Video" | 无障碍名称。 |
## 状态
- 画面区 16:9,黑底;字幕开启且有字幕时在底部显示。
- 字幕、画中画、全屏按钮开启时有选中底色和下划线。
## 事件
全部通过回调报告;组件不改动 `st`。
## 键盘操作
| 按键 | 作用 |
| --- | --- |
| Tab | 先聚焦画面,再到进度条和各按钮 |
| Space / K | 画面聚焦时播放或暂停 |
| ← / → | 画面聚焦时后退 / 前进 5 秒 |
| F | 切换全屏 |
| C | 切换字幕 |
## 限制
- 组件不解码视频,也不实现全屏或画中画窗口,只报告用户的请求。
- 帧率取决于调用方更新 `Frame` 并调用 `c.Invalidate()` 的频率。