01 gsy quickstart

From CarGuo/GSYVideoPlayer · View interactive version

01 gsy quickstart is an AI agent skill from the GitHub repository CarGuo/GSYVideoPlayer. 从零把 GSYVideoPlayer 塞进一个 Activity 或 Fragment,跑通「setUp → startPlayLogic → release」最小闭环。

How to use this skill

Skill file

gsy-quickstart

依赖

明细见 doc/DEPENDENCIES.md。

核心 API

| 类 / 方法 | 位置 | 作用 |

|---|---|---|

| StandardGSYVideoPlayer(Context) | StandardGSYVideoPlayer | 主用 UI 组件,默认布局在 R.layout.video_layout_standard |

| setUp(url, cacheWithPlay, title) | GSYVideoView#L438-L451 | 最短形式的地址绑定 |

| setUp(url, cacheWithPlay, cachePath, title) | GSYVideoView#L477-L488 | 支持自定义缓存目录 |

| setUp(url, cacheWithPlay, cachePath, headers, title) | GSYVideoView#L453-L475 | 附带 HTTP header |

| startPlayLogic() | StandardGSYVideoPlayer(继承自 GSYVideoControlView) | 触发 prepare→start 全流程 |

| getCurrentPlayer() | GSYBaseVideoPlayer | 获取"当前活跃 player"(可能是全屏克隆体) |

| onVideoPause() / onVideoResume() / onVideoResume(boolean seek) | GSYVideoView#L518-L577 | 对应 Activity onPause / onResume;直播场景传 seek=false |

| release() | GSYVideoView#L818 | 释放当前 Player 与 Surface |

| GSYVideoManager.releaseAllVideos() | GSYVideoManager#L99-L104 | 全局收尾(切页面时兜底) |

| GSYVideoManager.onPause() / onResume() | GSYVideoManager#L110-L135 | 全局暂停/恢复所有 GSY player |

参数表:`setUp(...)`

| 参数 | 类型 | 说明 |

|---|---|---|

| url | String | 支持 http/https/file/asset/rtmp/rtsp/自定义 scheme;ProxyCacheManager 会自动拦截可缓存的普通 http |

| cacheWithPlay | boolean | true → 边播边缓;对直播 / m3u8 / DRM 建议 false |

| cachePath | File? | 自定义缓存目录,默认 context.cacheDir/videoCache |

| mapHeadData | Map<String,String>? | HTTP 请求头(Referer、Cookie、Auth 等) |

| title | String | 顶部标题栏文案,会显示在 R.id.title |

返回值:boolean,false 表示 URL 为空或与当前 tag 相同(防重复 setup)。

最小调用序(Activity 生命周期)

  1. onCreate → player.setUp(...) → 可选 player.setThumb...、setPlayTag() → player.startPlayLogic()
  2. onPause → player.getCurrentPlayer().onVideoPause()
  3. onResume → player.getCurrentPlayer().onVideoResume()(直播传 false)
  4. onBackPressed → 若在全屏:GSYVideoManager.backFromWindowFull(this) 返回 true 就吞掉事件
  5. onDestroy → player.getCurrentPlayer().release() + GSYVideoManager.releaseAllVideos()

Demo 对照

常见坑

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.