Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

自定义界面

fengxing edited this page Nov 22, 2018 · 1 revision

自定义界面

在使用SuperPlayer时,通常都会对界面做一些修改。在播放器中,我们编写的界面相关代码有:首屏、进度缓冲、错误提示、播放结束和播放控制。其中播放控制最有可能被修改,因此将其抽象出SuperPlayerControlView这个类。

实现原理

SuperPlayerView会在播放过程中会调用下面这些方法更新状态

@interface SuperPlayerControlView : UIView
/**
 * 播放进度
 * @param currentTime 当前播放时长
 * @param totalTime 视频总时长
 * @param progress value(0.0~1.0)
 * @param playable value(0.0~1.0)
 */
- (void)setProgressTime:(NSInteger)currentTime totalTime:(NSInteger)totalTime
 progressValue:(CGFloat)progress playableValue:(CGFloat)playable;
/**
 * 播放状态
 * @param isPlay YES播放,NO暂停
 */
- (void)setPlayState:(BOOL)isPlay;
/**
 * 开始新的播放
 * @param isLive 是否为直播流
 * @param isTimeShifting 是否在直播时移
 * @param isAutoPlay 是否自动播放
 */
- (void)playerBegin:(SuperPlayerModel *)model
 isLive:(BOOL)isLive
 isTimeShifting:(BOOL)isTimeShifting
 isAutoPlay:(BOOL)isAutoPlay;
@end

其它诸如 title、pointArray等为可选接口。

控制层的界面事件最终通过delegate回调的方式通知到SuperPlayerView

@protocol SuperPlayerControlViewDelegate <NSObject>
/** 返回按钮事件 */
- (void)controlViewBack:(UIView *)controlView;
/** 播放 */
- (void)controlViewPlay:(UIView *)controlView;
/** 暂停 */
- (void)controlViewPause:(UIView *)controlView;
/** 播放器全屏 */
- (void)controlViewChangeScreen:(UIView *)controlView withFullScreen:(BOOL)isFullScreen;
/** 锁定屏幕方向 */
- (void)controlViewLockScreen:(UIView *)controlView withLock:(BOOL)islock;
/** 截屏事件 */
- (void)controlViewSnapshot:(UIView *)controlView;
/** 切换分辨率按钮事件 */
- (void)controlViewSwitch:(UIView *)controlView withDefinition:(NSString *)definition;
/** 修改配置 */
- (void)controlViewConfigUpdate:(SuperPlayerControlView *)controlView;
/** 重新播放 */
- (void)controlViewReload:(UIView *)controlView;
/** seek事件,pos 0~1 */
- (void)controlViewSeek:(UIView *)controlView where:(CGFloat)pos;
/** 滑动预览,pos 0~1 */
- (void)controlViewPreview:(UIView *)controlView where:(CGFloat)pos;
@end

修改默认界面

播放的默认控制界面是 SPDefaultControlView,可以通过下面方式获取到。

SPDefaultControlView *controlView = (SPDefaultControlView *)player.controlView;

举个栗子,比如有隐藏弹幕按钮需求。弹幕按钮在横屏时才会显示,那么我们可以在全屏事件中,直接将其隐藏

- (void)superPlayerFullScreenChanged:(SuperPlayerView *)player {
 if (player.isFullScreen) {
 SPDefaultControlView *controlView = (SPDefaultControlView *)player.controlView;
 controlView.danmakuBtn.hidden = YES;
 }
}

自定义皮肤

上面的这种修改只适用于简单需求,如果修改较大建议将SPDefaultControlView拷贝出来,自己修改代码。SPWeiboController是一个简单修改的示例。

player.controlView = # 你的播放控制层 #

设置controlView,控制层立即生效。

Clone this wiki locally

AltStyle によって変換されたページ (->オリジナル) /