12 gsy custom view

From CarGuo/GSYVideoPlayer · View interactive version

12 gsy custom view is an AI agent skill from the GitHub repository CarGuo/GSYVideoPlayer. 自定义播放器 UI(继承 StandardGSYVideoPlayer)与自定义控制层:换 seekbar、加弹幕层、加清晰度切换、加投屏按钮等。

How to use this skill

Skill file

gsy-custom-view

继承层次

GSYTextureRenderView(渲染管理)
  └── GSYVideoView(状态机 / 生命周期)
        └── GSYVideoControlView(默认控制层:进度条/按钮)
              └── GSYVideoPlayer(触摸手势)
                    └── GSYBaseVideoPlayer(全屏/小屏切换)
                          ├── StandardGSYVideoPlayer(默认 UI)
                          └── NormalGSYVideoPlayer(无返回/无标题的简版)

自定义组件通常继承 StandardGSYVideoPlayer 或 NormalGSYVideoPlayer。

必须实现的三件事

1) 自定义布局 & id

覆写:

@Override public int getLayoutId() { return R.layout.my_video_player; }

布局里必须包含(id 不能改):

2) 覆写全屏 & 小屏组件类

关键:getConstructor(Context, Boolean) 是 SDK 内部反射拷贝出的全屏实例。必须提供两个构造器:

public MyVideoPlayer(Context c) { super(c); }
public MyVideoPlayer(Context c, Boolean fullFlag) { super(c, fullFlag); }
public MyVideoPlayer(Context c, AttributeSet a) { super(c, a); }

R8 侧已在 proguard-rules.pro 保留:

-keep class * extends com.shuyu.gsyvideoplayer.video.base.GSYBaseVideoPlayer {
    public <init>(android.content.Context);
    public <init>(android.content.Context, java.lang.Boolean);
}

3) 覆写 `showSmallVideo() / hideSmallVideo()`(如需要小窗)以及 `startWindowFullscreen()`(如要全屏样式差异)

常用重写点

| 方法 | 作用 |

|---|---|

| changeUiToNormal() / changeUiToPreparingShow() / changeUiToPlayingShow() / changeUiToPauseShow() / changeUiToCompleteShow() / changeUiToError() / changeUiToPlayingBufferingShow() | 不同状态下的 UI 切换钩子 |

| onClickUiToggle() | 单击 UI 显隐 |

| setStateAndUi(int state) | 由 SDK 内部调,可 super 后加自己的逻辑 |

| updateStartImage() | 播放/暂停按钮 icon 切换 |

| resolveTypeUI() | 首帧比例决定后的自定义处理 |

| dismissBrightnessDialog / dismissVolumeDialog / dismissProgressDialog | 手势弹窗 UI |

| hideAllWidget / setViewShowState | 显隐所有控件 |

手势自定义

GSYVideoControlView 里通过如下开关切换:

手势弹窗替换:覆写 showBrightnessDialog / showVolumeDialog / showProgressDialog 用自己的 Dialog。

标准封面 / 清晰度 / 弹幕

多状态视图(loading / error / paywall)

在 changeUiToError() 与 changeUiToPreparingShow() 里 setVisibility 自定义 View;也可以在 onVideoAllCallBack.onPlayError 中显式 showErrorLayer()。

常见坑

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.