hyzp_ybqx-Commit001:代码刚转换好,编译通过
This commit is contained in:
@@ -0,0 +1,79 @@
|
||||
//
|
||||
// SPDefaultControlView.h
|
||||
// SuperPlayer
|
||||
//
|
||||
// Created by annidyfeng on 2018/9/30.
|
||||
//
|
||||
|
||||
#import "SuperPlayerControlView.h"
|
||||
|
||||
@interface SPDefaultControlView : SuperPlayerControlView
|
||||
|
||||
|
||||
/** 标题 */
|
||||
@property (nonatomic, strong) UILabel *titleLabel;
|
||||
/** 开始播放按钮 */
|
||||
@property (nonatomic, strong) UIButton *startBtn;
|
||||
/** 当前播放时长label */
|
||||
@property (nonatomic, strong) UILabel *currentTimeLabel;
|
||||
/** 视频总时长label */
|
||||
@property (nonatomic, strong) UILabel *totalTimeLabel;
|
||||
/** 全屏按钮 */
|
||||
@property (nonatomic, strong) UIButton *fullScreenBtn;
|
||||
/** 锁定屏幕方向按钮 */
|
||||
@property (nonatomic, strong) UIButton *lockBtn;
|
||||
|
||||
/** 返回按钮*/
|
||||
@property (nonatomic, strong) UIButton *backBtn;
|
||||
/// 是否禁用返回
|
||||
@property (nonatomic) BOOL disableBackBtn;
|
||||
/** bottomView*/
|
||||
@property (nonatomic, strong) UIImageView *bottomImageView;
|
||||
/** topView */
|
||||
@property (nonatomic, strong) UIImageView *topImageView;
|
||||
/** 弹幕按钮 */
|
||||
@property (nonatomic, strong) UIButton *danmakuBtn;
|
||||
/// 是否禁用弹幕
|
||||
@property (nonatomic) BOOL disableDanmakuBtn;
|
||||
/** 截图按钮 */
|
||||
@property (nonatomic, strong) UIButton *captureBtn;
|
||||
/// 是否禁用截图
|
||||
@property (nonatomic) BOOL disableCaptureBtn;
|
||||
/** 更多按钮 */
|
||||
@property (nonatomic, strong) UIButton *moreBtn;
|
||||
/// 是否禁用更多
|
||||
@property (nonatomic) BOOL disableMoreBtn;
|
||||
/** 切换分辨率按钮 */
|
||||
@property (nonatomic, strong) UIButton *resolutionBtn;
|
||||
/** 分辨率的View */
|
||||
@property (nonatomic, strong) UIView *resolutionView;
|
||||
/** 播放按钮 */
|
||||
@property (nonatomic, strong) UIButton *playeBtn;
|
||||
/** 加载失败按钮 */
|
||||
@property (nonatomic, strong) UIButton *middleBtn;
|
||||
|
||||
/** 当前选中的分辨率btn按钮 */
|
||||
@property (nonatomic, weak ) UIButton *resoultionCurrentBtn;
|
||||
|
||||
/** 分辨率的名称 */
|
||||
@property (nonatomic, strong) NSArray<NSString *> *resolutionArray;
|
||||
/** 更多设置View */
|
||||
@property (nonatomic, strong) SuperPlayerSettingsView *moreContentView;
|
||||
/** 返回直播 */
|
||||
@property (nonatomic, strong) UIButton *backLiveBtn;
|
||||
|
||||
/// 画面比例
|
||||
@property CGFloat videoRatio;
|
||||
|
||||
/** 滑杆 */
|
||||
@property (nonatomic, strong) PlayerSlider *videoSlider;
|
||||
|
||||
/** 重播按钮 */
|
||||
@property (nonatomic, strong) UIButton *repeatBtn;
|
||||
|
||||
/** 是否全屏播放 */
|
||||
@property (nonatomic, assign,getter=isFullScreen)BOOL fullScreen;
|
||||
@property (nonatomic, assign,getter=isLockScreen)BOOL isLockScreen;
|
||||
@property (nonatomic, strong) UIButton *pointJumpBtn;
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,774 @@
|
||||
#import "SuperPlayerControlView.h"
|
||||
#import <AVFoundation/AVFoundation.h>
|
||||
#import <MediaPlayer/MediaPlayer.h>
|
||||
|
||||
#import "SuperPlayerSettingsView.h"
|
||||
#import "DataReport.h"
|
||||
#import "SuperPlayerFastView.h"
|
||||
#import "PlayerSlider.h"
|
||||
#import "UIView+MMLayout.h"
|
||||
#import "SuperPlayerView+Private.h"
|
||||
#import "StrUtils.h"
|
||||
#import "SPDefaultControlView.h"
|
||||
#import "UIView+Fade.h"
|
||||
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored"-Wdeprecated-declarations"
|
||||
|
||||
#define MODEL_TAG_BEGIN 20
|
||||
#define BOTTOM_IMAGE_VIEW_HEIGHT 50
|
||||
|
||||
@interface SPDefaultControlView () <UIGestureRecognizerDelegate, PlayerSliderDelegate>
|
||||
@property BOOL isLive;
|
||||
@end
|
||||
|
||||
@implementation SPDefaultControlView
|
||||
|
||||
- (instancetype)initWithFrame:(CGRect)frame {
|
||||
self = [super initWithFrame:frame];
|
||||
if (self) {
|
||||
[self addSubview:self.topImageView];
|
||||
[self addSubview:self.bottomImageView];
|
||||
[self.bottomImageView addSubview:self.startBtn];
|
||||
[self.bottomImageView addSubview:self.currentTimeLabel];
|
||||
[self.bottomImageView addSubview:self.videoSlider];
|
||||
[self.bottomImageView addSubview:self.resolutionBtn];
|
||||
[self.bottomImageView addSubview:self.fullScreenBtn];
|
||||
[self.bottomImageView addSubview:self.totalTimeLabel];
|
||||
|
||||
[self.topImageView addSubview:self.captureBtn];
|
||||
[self.topImageView addSubview:self.danmakuBtn];
|
||||
[self.topImageView addSubview:self.moreBtn];
|
||||
[self addSubview:self.lockBtn];
|
||||
[self.topImageView addSubview:self.backBtn];
|
||||
|
||||
[self addSubview:self.playeBtn];
|
||||
|
||||
[self.topImageView addSubview:self.titleLabel];
|
||||
|
||||
|
||||
[self addSubview:self.backLiveBtn];
|
||||
|
||||
// 添加子控件的约束
|
||||
[self makeSubViewsConstraints];
|
||||
|
||||
self.captureBtn.hidden = YES;
|
||||
self.danmakuBtn.hidden = YES;
|
||||
self.moreBtn.hidden = YES;
|
||||
self.resolutionBtn.hidden = YES;
|
||||
self.moreContentView.hidden = YES;
|
||||
// 初始化时重置controlView
|
||||
[self playerResetControlView];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)dealloc {
|
||||
[[NSNotificationCenter defaultCenter] removeObserver:self];
|
||||
}
|
||||
|
||||
- (void)makeSubViewsConstraints {
|
||||
|
||||
[self.topImageView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.leading.trailing.equalTo(self);
|
||||
make.top.equalTo(self.mas_top).offset(0);
|
||||
make.height.mas_equalTo(50);
|
||||
}];
|
||||
|
||||
[self.backBtn mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.leading.equalTo(self.topImageView.mas_leading).offset(5);
|
||||
make.top.equalTo(self.topImageView.mas_top).offset(3);
|
||||
make.width.height.mas_equalTo(40);
|
||||
}];
|
||||
|
||||
[self.moreBtn mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.width.mas_equalTo(40);
|
||||
make.height.mas_equalTo(49);
|
||||
make.trailing.equalTo(self.topImageView.mas_trailing).offset(-10);
|
||||
make.centerY.equalTo(self.backBtn.mas_centerY);
|
||||
}];
|
||||
|
||||
[self.captureBtn mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.width.mas_equalTo(40);
|
||||
make.height.mas_equalTo(49);
|
||||
make.trailing.equalTo(self.moreBtn.mas_leading).offset(-10);
|
||||
make.centerY.equalTo(self.backBtn.mas_centerY);
|
||||
}];
|
||||
|
||||
[self.danmakuBtn mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.width.mas_equalTo(40);
|
||||
make.height.mas_equalTo(49);
|
||||
make.trailing.equalTo(self.captureBtn.mas_leading).offset(-10);
|
||||
make.centerY.equalTo(self.backBtn.mas_centerY);
|
||||
}];
|
||||
|
||||
[self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.leading.equalTo(self.backBtn.mas_trailing).offset(5);
|
||||
make.centerY.equalTo(self.backBtn.mas_centerY);
|
||||
make.trailing.equalTo(self.captureBtn.mas_leading).offset(-10);
|
||||
}];
|
||||
|
||||
[self.bottomImageView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.leading.trailing.bottom.mas_equalTo(0);
|
||||
make.height.mas_equalTo(BOTTOM_IMAGE_VIEW_HEIGHT);
|
||||
}];
|
||||
|
||||
[self.startBtn mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.leading.equalTo(self.bottomImageView.mas_leading).offset(5);
|
||||
make.top.equalTo(self.bottomImageView.mas_top).offset(10);
|
||||
make.width.height.mas_equalTo(30);
|
||||
}];
|
||||
|
||||
[self.currentTimeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.leading.equalTo(self.startBtn.mas_trailing);
|
||||
make.centerY.equalTo(self.startBtn.mas_centerY);
|
||||
make.width.mas_equalTo(60);
|
||||
}];
|
||||
|
||||
[self.fullScreenBtn mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.width.height.mas_equalTo(30);
|
||||
make.trailing.equalTo(self.bottomImageView.mas_trailing).offset(-8);
|
||||
make.centerY.equalTo(self.startBtn.mas_centerY);
|
||||
}];
|
||||
|
||||
[self.resolutionBtn mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.height.mas_equalTo(30);
|
||||
make.width.mas_greaterThanOrEqualTo(45);
|
||||
make.trailing.equalTo(self.bottomImageView.mas_trailing).offset(-8);
|
||||
make.centerY.equalTo(self.startBtn.mas_centerY);
|
||||
}];
|
||||
|
||||
[self.totalTimeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.trailing.equalTo(self.fullScreenBtn.mas_leading);
|
||||
make.centerY.equalTo(self.startBtn.mas_centerY);
|
||||
make.width.mas_equalTo(60);
|
||||
}];
|
||||
|
||||
[self.videoSlider mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.leading.equalTo(self.currentTimeLabel.mas_trailing);
|
||||
make.trailing.equalTo(self.totalTimeLabel.mas_leading);
|
||||
make.centerY.equalTo(self.currentTimeLabel.mas_centerY).offset(-1);
|
||||
}];
|
||||
|
||||
[self.lockBtn mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.leading.equalTo(self.mas_leading).offset(15);
|
||||
make.centerY.equalTo(self.mas_centerY);
|
||||
make.width.height.mas_equalTo(32);
|
||||
}];
|
||||
|
||||
|
||||
[self.playeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.width.height.mas_equalTo(50);
|
||||
make.center.equalTo(self);
|
||||
}];
|
||||
|
||||
|
||||
[self.backLiveBtn mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.bottom.mas_equalTo(self.startBtn.mas_top).mas_offset(-15);
|
||||
make.width.mas_equalTo(70);
|
||||
make.centerX.equalTo(self);
|
||||
}];
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
#pragma mark - Action
|
||||
|
||||
/**
|
||||
* 点击切换分别率按钮
|
||||
*/
|
||||
- (void)changeResolution:(UIButton *)sender {
|
||||
self.resoultionCurrentBtn.selected = NO;
|
||||
self.resoultionCurrentBtn.backgroundColor = [UIColor clearColor];
|
||||
self.resoultionCurrentBtn = sender;
|
||||
self.resoultionCurrentBtn.selected = YES;
|
||||
self.resoultionCurrentBtn.backgroundColor = RGBA(34, 30, 24, 1);
|
||||
|
||||
// topImageView上的按钮的文字
|
||||
[self.resolutionBtn setTitle:sender.titleLabel.text forState:UIControlStateNormal];
|
||||
[self.delegate controlViewSwitch:self withDefinition:sender.titleLabel.text];
|
||||
}
|
||||
|
||||
- (void)backBtnClick:(UIButton *)sender {
|
||||
if ([self.delegate respondsToSelector:@selector(controlViewBack:)]) {
|
||||
[self.delegate controlViewBack:self];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)exitFullScreen:(UIButton *)sender {
|
||||
if ([self.delegate respondsToSelector:@selector(controlViewChangeScreen:withFullScreen:)]) {
|
||||
[self.delegate controlViewChangeScreen:self withFullScreen:NO];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)lockScrrenBtnClick:(UIButton *)sender {
|
||||
sender.selected = !sender.selected;
|
||||
self.isLockScreen = sender.selected;
|
||||
self.topImageView.hidden = self.isLockScreen;
|
||||
self.bottomImageView.hidden = self.isLockScreen;
|
||||
if (self.isLive) {
|
||||
self.backLiveBtn.hidden = self.isLockScreen;
|
||||
}
|
||||
[self.delegate controlViewLockScreen:self withLock:self.isLockScreen];
|
||||
[self fadeOut:3];
|
||||
}
|
||||
|
||||
- (void)playBtnClick:(UIButton *)sender {
|
||||
sender.selected = !sender.selected;
|
||||
if (sender.selected) {
|
||||
[self.delegate controlViewPlay:self];
|
||||
} else {
|
||||
[self.delegate controlViewPause:self];
|
||||
}
|
||||
[self cancelFadeOut];
|
||||
}
|
||||
|
||||
- (void)fullScreenBtnClick:(UIButton *)sender {
|
||||
sender.selected = !sender.selected;
|
||||
self.fullScreen = !self.fullScreen;
|
||||
[self.delegate controlViewChangeScreen:self withFullScreen:YES];
|
||||
[self fadeOut:3];
|
||||
}
|
||||
|
||||
|
||||
- (void)captureBtnClick:(UIButton *)sender {
|
||||
[self.delegate controlViewSnapshot:self];
|
||||
[self fadeOut:3];
|
||||
}
|
||||
|
||||
- (void)danmakuBtnClick:(UIButton *)sender {
|
||||
sender.selected = !sender.selected;
|
||||
[self fadeOut:3];
|
||||
}
|
||||
|
||||
- (void)moreBtnClick:(UIButton *)sender {
|
||||
self.topImageView.hidden = YES;
|
||||
self.bottomImageView.hidden = YES;
|
||||
self.lockBtn.hidden = YES;
|
||||
|
||||
self.moreContentView.playerConfig = self.playerConfig;
|
||||
[self.moreContentView update];
|
||||
self.moreContentView.hidden = NO;
|
||||
|
||||
[self cancelFadeOut];
|
||||
self.isShowSecondView = YES;
|
||||
}
|
||||
|
||||
- (UIView *)resolutionView {
|
||||
if (!_resolutionView) {
|
||||
// 添加分辨率按钮和分辨率下拉列表
|
||||
|
||||
_resolutionView = [[UIView alloc] initWithFrame:CGRectZero];
|
||||
_resolutionView.hidden = YES;
|
||||
[self addSubview:_resolutionView];
|
||||
[_resolutionView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.width.mas_equalTo(330);
|
||||
make.height.mas_equalTo(self.mas_height);
|
||||
make.trailing.equalTo(self.mas_trailing).offset(0);
|
||||
make.top.equalTo(self.mas_top).offset(0);
|
||||
}];
|
||||
|
||||
_resolutionView.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.5];
|
||||
}
|
||||
return _resolutionView;
|
||||
}
|
||||
|
||||
- (void)resolutionBtnClick:(UIButton *)sender {
|
||||
self.topImageView.hidden = YES;
|
||||
self.bottomImageView.hidden = YES;
|
||||
self.lockBtn.hidden = YES;
|
||||
|
||||
// 显示隐藏分辨率View
|
||||
self.resolutionView.hidden = NO;
|
||||
[DataReport report:@"change_resolution" param:nil];
|
||||
|
||||
[self cancelFadeOut];
|
||||
self.isShowSecondView = YES;
|
||||
}
|
||||
|
||||
- (void)progressSliderTouchBegan:(UISlider *)sender {
|
||||
self.isDragging = YES;
|
||||
[self cancelFadeOut];
|
||||
}
|
||||
|
||||
- (void)progressSliderValueChanged:(UISlider *)sender {
|
||||
if (self.maxPlayableRatio > 0 && sender.value > self.maxPlayableRatio) {
|
||||
sender.value = self.maxPlayableRatio;
|
||||
}
|
||||
[self.delegate controlViewPreview:self where:sender.value];
|
||||
}
|
||||
|
||||
- (void)progressSliderTouchEnded:(UISlider *)sender {
|
||||
[self.delegate controlViewSeek:self where:sender.value];
|
||||
self.isDragging = NO;
|
||||
[self fadeOut:5];
|
||||
}
|
||||
|
||||
- (void)backLiveClick:(UIButton *)sender {
|
||||
[self.delegate controlViewReload:self];
|
||||
}
|
||||
|
||||
- (void)pointJumpClick:(UIButton *)sender {
|
||||
self.pointJumpBtn.hidden = YES;
|
||||
PlayerPoint *point = [self.videoSlider.pointArray objectAtIndex:self.pointJumpBtn.tag];
|
||||
[self.delegate controlViewSeek:self where:point.where];
|
||||
[self fadeOut:0.1];
|
||||
}
|
||||
|
||||
- (void)setDisableBackBtn:(BOOL)disableBackBtn {
|
||||
_disableBackBtn = disableBackBtn;
|
||||
self.backBtn.hidden = disableBackBtn;
|
||||
}
|
||||
|
||||
- (void)setDisableMoreBtn:(BOOL)disableMoreBtn {
|
||||
_disableMoreBtn = disableMoreBtn;
|
||||
if (self.fullScreen) {
|
||||
self.moreBtn.hidden = disableMoreBtn;
|
||||
}
|
||||
}
|
||||
|
||||
- (void)setDisableCaptureBtn:(BOOL)disableCaptureBtn {
|
||||
_disableCaptureBtn = disableCaptureBtn;
|
||||
if (self.fullScreen) {
|
||||
self.captureBtn.hidden = disableCaptureBtn;
|
||||
}
|
||||
}
|
||||
|
||||
- (void)setDisableDanmakuBtn:(BOOL)disableDanmakuBtn {
|
||||
_disableDanmakuBtn = disableDanmakuBtn;
|
||||
if (self.fullScreen) {
|
||||
self.danmakuBtn.hidden = disableDanmakuBtn;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 屏幕方向发生变化会调用这里
|
||||
*/
|
||||
- (void)setOrientationLandscapeConstraint {
|
||||
self.fullScreen = YES;
|
||||
self.lockBtn.hidden = NO;
|
||||
self.fullScreenBtn.selected = self.isLockScreen;
|
||||
self.fullScreenBtn.hidden = YES;
|
||||
self.resolutionBtn.hidden = self.resolutionArray.count == 0;
|
||||
self.moreBtn.hidden = self.disableMoreBtn;
|
||||
self.captureBtn.hidden = self.disableCaptureBtn;
|
||||
self.danmakuBtn.hidden = self.disableDanmakuBtn;
|
||||
|
||||
[self.backBtn setImage:SuperPlayerImage(@"back_full") forState:UIControlStateNormal];
|
||||
[self.totalTimeLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
|
||||
if (self.resolutionArray.count > 0) {
|
||||
make.trailing.equalTo(self.resolutionBtn.mas_leading);
|
||||
} else {
|
||||
make.trailing.equalTo(self.bottomImageView.mas_trailing);
|
||||
}
|
||||
make.centerY.equalTo(self.startBtn.mas_centerY);
|
||||
make.width.mas_equalTo(self.isLive?10:60);
|
||||
}];
|
||||
|
||||
[self.bottomImageView mas_updateConstraints:^(MASConstraintMaker *make) {
|
||||
CGFloat b = self.superview.mm_safeAreaBottomGap;
|
||||
make.height.mas_equalTo(BOTTOM_IMAGE_VIEW_HEIGHT+b);
|
||||
}];
|
||||
|
||||
self.videoSlider.hiddenPoints = NO;
|
||||
}
|
||||
/**
|
||||
* 设置竖屏的约束
|
||||
*/
|
||||
- (void)setOrientationPortraitConstraint {
|
||||
self.fullScreen = NO;
|
||||
self.lockBtn.hidden = YES;
|
||||
self.fullScreenBtn.selected = NO;
|
||||
self.fullScreenBtn.hidden = NO;
|
||||
self.resolutionBtn.hidden = YES;
|
||||
self.moreBtn.hidden = YES;
|
||||
self.captureBtn.hidden = YES;
|
||||
self.danmakuBtn.hidden = YES;
|
||||
self.moreContentView.hidden = YES;
|
||||
self.resolutionView.hidden = YES;
|
||||
|
||||
[self.totalTimeLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
|
||||
make.trailing.equalTo(self.fullScreenBtn.mas_leading);
|
||||
make.centerY.equalTo(self.startBtn.mas_centerY);
|
||||
make.width.mas_equalTo(self.isLive?10:60);
|
||||
}];
|
||||
|
||||
[self.bottomImageView mas_updateConstraints:^(MASConstraintMaker *make) {
|
||||
make.height.mas_equalTo(BOTTOM_IMAGE_VIEW_HEIGHT);
|
||||
}];
|
||||
|
||||
self.videoSlider.hiddenPoints = YES;
|
||||
self.pointJumpBtn.hidden = YES;
|
||||
}
|
||||
|
||||
#pragma mark - Private Method
|
||||
|
||||
#pragma mark - setter
|
||||
|
||||
- (UILabel *)titleLabel {
|
||||
if (!_titleLabel) {
|
||||
_titleLabel = [[UILabel alloc] init];
|
||||
_titleLabel.textColor = [UIColor whiteColor];
|
||||
_titleLabel.font = [UIFont systemFontOfSize:15.0];
|
||||
}
|
||||
return _titleLabel;
|
||||
}
|
||||
|
||||
- (UIButton *)backBtn {
|
||||
if (!_backBtn) {
|
||||
_backBtn = [UIButton buttonWithType:UIButtonTypeCustom];
|
||||
[_backBtn setImage:SuperPlayerImage(@"back_full") forState:UIControlStateNormal];
|
||||
[_backBtn addTarget:self action:@selector(backBtnClick:) forControlEvents:UIControlEventTouchUpInside];
|
||||
}
|
||||
return _backBtn;
|
||||
}
|
||||
|
||||
- (UIImageView *)topImageView {
|
||||
if (!_topImageView) {
|
||||
_topImageView = [[UIImageView alloc] init];
|
||||
_topImageView.userInteractionEnabled = YES;
|
||||
_topImageView.image = SuperPlayerImage(@"top_shadow");
|
||||
}
|
||||
return _topImageView;
|
||||
}
|
||||
|
||||
- (UIImageView *)bottomImageView {
|
||||
if (!_bottomImageView) {
|
||||
_bottomImageView = [[UIImageView alloc] init];
|
||||
_bottomImageView.userInteractionEnabled = YES;
|
||||
_bottomImageView.image = SuperPlayerImage(@"bottom_shadow");
|
||||
}
|
||||
return _bottomImageView;
|
||||
}
|
||||
|
||||
- (UIButton *)lockBtn {
|
||||
if (!_lockBtn) {
|
||||
_lockBtn = [UIButton buttonWithType:UIButtonTypeCustom];
|
||||
_lockBtn.exclusiveTouch = YES;
|
||||
[_lockBtn setImage:SuperPlayerImage(@"unlock-nor") forState:UIControlStateNormal];
|
||||
[_lockBtn setImage:SuperPlayerImage(@"lock-nor") forState:UIControlStateSelected];
|
||||
[_lockBtn addTarget:self action:@selector(lockScrrenBtnClick:) forControlEvents:UIControlEventTouchUpInside];
|
||||
|
||||
}
|
||||
return _lockBtn;
|
||||
}
|
||||
|
||||
- (UIButton *)startBtn {
|
||||
if (!_startBtn) {
|
||||
_startBtn = [UIButton buttonWithType:UIButtonTypeCustom];
|
||||
[_startBtn setImage:SuperPlayerImage(@"play") forState:UIControlStateNormal];
|
||||
[_startBtn setImage:SuperPlayerImage(@"pause") forState:UIControlStateSelected];
|
||||
[_startBtn addTarget:self action:@selector(playBtnClick:) forControlEvents:UIControlEventTouchUpInside];
|
||||
}
|
||||
return _startBtn;
|
||||
}
|
||||
|
||||
- (UILabel *)currentTimeLabel {
|
||||
if (!_currentTimeLabel) {
|
||||
_currentTimeLabel = [[UILabel alloc] init];
|
||||
_currentTimeLabel.textColor = [UIColor whiteColor];
|
||||
_currentTimeLabel.font = [UIFont systemFontOfSize:12.0f];
|
||||
_currentTimeLabel.textAlignment = NSTextAlignmentCenter;
|
||||
}
|
||||
return _currentTimeLabel;
|
||||
}
|
||||
|
||||
- (PlayerSlider *)videoSlider {
|
||||
if (!_videoSlider) {
|
||||
_videoSlider = [[PlayerSlider alloc] init];
|
||||
[_videoSlider setThumbImage:SuperPlayerImage(@"slider_thumb") forState:UIControlStateNormal];
|
||||
_videoSlider.minimumTrackTintColor = TintColor;
|
||||
// slider开始滑动事件
|
||||
[_videoSlider addTarget:self action:@selector(progressSliderTouchBegan:) forControlEvents:UIControlEventTouchDown];
|
||||
// slider滑动中事件
|
||||
[_videoSlider addTarget:self action:@selector(progressSliderValueChanged:) forControlEvents:UIControlEventValueChanged];
|
||||
// slider结束滑动事件
|
||||
[_videoSlider addTarget:self action:@selector(progressSliderTouchEnded:) forControlEvents:UIControlEventTouchUpInside | UIControlEventTouchUpOutside];
|
||||
_videoSlider.delegate = self;
|
||||
}
|
||||
return _videoSlider;
|
||||
}
|
||||
|
||||
- (UILabel *)totalTimeLabel {
|
||||
if (!_totalTimeLabel) {
|
||||
_totalTimeLabel = [[UILabel alloc] init];
|
||||
_totalTimeLabel.textColor = [UIColor whiteColor];
|
||||
_totalTimeLabel.font = [UIFont systemFontOfSize:12.0f];
|
||||
_totalTimeLabel.textAlignment = NSTextAlignmentCenter;
|
||||
}
|
||||
return _totalTimeLabel;
|
||||
}
|
||||
|
||||
- (UIButton *)fullScreenBtn {
|
||||
if (!_fullScreenBtn) {
|
||||
_fullScreenBtn = [UIButton buttonWithType:UIButtonTypeCustom];
|
||||
[_fullScreenBtn setImage:SuperPlayerImage(@"fullscreen") forState:UIControlStateNormal];
|
||||
[_fullScreenBtn addTarget:self action:@selector(fullScreenBtnClick:) forControlEvents:UIControlEventTouchUpInside];
|
||||
}
|
||||
return _fullScreenBtn;
|
||||
}
|
||||
|
||||
- (UIButton *)captureBtn {
|
||||
if (!_captureBtn) {
|
||||
_captureBtn = [UIButton buttonWithType:UIButtonTypeCustom];
|
||||
[_captureBtn setImage:SuperPlayerImage(@"capture") forState:UIControlStateNormal];
|
||||
[_captureBtn setImage:SuperPlayerImage(@"capture_pressed") forState:UIControlStateSelected];
|
||||
[_captureBtn addTarget:self action:@selector(captureBtnClick:) forControlEvents:UIControlEventTouchUpInside];
|
||||
}
|
||||
return _captureBtn;
|
||||
}
|
||||
|
||||
- (UIButton *)danmakuBtn {
|
||||
if (!_danmakuBtn) {
|
||||
_danmakuBtn = [UIButton buttonWithType:UIButtonTypeCustom];
|
||||
[_danmakuBtn setImage:SuperPlayerImage(@"danmu") forState:UIControlStateNormal];
|
||||
[_danmakuBtn setImage:SuperPlayerImage(@"danmu_pressed") forState:UIControlStateSelected];
|
||||
[_danmakuBtn addTarget:self action:@selector(danmakuBtnClick:) forControlEvents:UIControlEventTouchUpInside];
|
||||
}
|
||||
return _danmakuBtn;
|
||||
}
|
||||
|
||||
- (UIButton *)moreBtn {
|
||||
if (!_moreBtn) {
|
||||
_moreBtn = [UIButton buttonWithType:UIButtonTypeCustom];
|
||||
[_moreBtn setImage:SuperPlayerImage(@"more") forState:UIControlStateNormal];
|
||||
[_moreBtn setImage:SuperPlayerImage(@"more_pressed") forState:UIControlStateSelected];
|
||||
[_moreBtn addTarget:self action:@selector(moreBtnClick:) forControlEvents:UIControlEventTouchUpInside];
|
||||
}
|
||||
return _moreBtn;
|
||||
}
|
||||
|
||||
- (UIButton *)resolutionBtn {
|
||||
if (!_resolutionBtn) {
|
||||
_resolutionBtn = [UIButton buttonWithType:UIButtonTypeCustom];
|
||||
_resolutionBtn.titleLabel.font = [UIFont systemFontOfSize:12];
|
||||
_resolutionBtn.backgroundColor = [UIColor clearColor];
|
||||
[_resolutionBtn addTarget:self action:@selector(resolutionBtnClick:) forControlEvents:UIControlEventTouchUpInside];
|
||||
}
|
||||
return _resolutionBtn;
|
||||
}
|
||||
|
||||
- (UIButton *)backLiveBtn {
|
||||
if (!_backLiveBtn) {
|
||||
_backLiveBtn = [UIButton buttonWithType:UIButtonTypeCustom];
|
||||
[_backLiveBtn setTitle:@"返回直播" forState:UIControlStateNormal];
|
||||
_backLiveBtn.titleLabel.font = [UIFont systemFontOfSize:14];
|
||||
UIImage *image = SuperPlayerImage(@"qg_online_bg");
|
||||
|
||||
UIImage *resizableImage = [image resizableImageWithCapInsets:UIEdgeInsetsMake(33 * 0.5, 33 * 0.5, 33 * 0.5, 33 * 0.5)];
|
||||
[_backLiveBtn setBackgroundImage:resizableImage forState:UIControlStateNormal];
|
||||
|
||||
[_backLiveBtn addTarget:self action:@selector(backLiveClick:) forControlEvents:UIControlEventTouchUpInside];
|
||||
}
|
||||
return _backLiveBtn;
|
||||
}
|
||||
|
||||
- (UIButton *)pointJumpBtn {
|
||||
if (!_pointJumpBtn) {
|
||||
_pointJumpBtn = [UIButton buttonWithType:UIButtonTypeCustom];
|
||||
UIImage *image = SuperPlayerImage(@"copywright_bg");
|
||||
UIImage *resizableImage = [image resizableImageWithCapInsets:UIEdgeInsetsMake(0, 20, 0, 20) resizingMode:UIImageResizingModeStretch];
|
||||
[_pointJumpBtn setBackgroundImage:resizableImage forState:UIControlStateNormal];
|
||||
_pointJumpBtn.titleLabel.font = [UIFont systemFontOfSize:14];
|
||||
[_pointJumpBtn addTarget:self action:@selector(pointJumpClick:) forControlEvents:UIControlEventTouchUpInside];
|
||||
[self addSubview:_pointJumpBtn];
|
||||
}
|
||||
return _pointJumpBtn;
|
||||
}
|
||||
|
||||
- (SuperPlayerSettingsView *)moreContentView {
|
||||
if (!_moreContentView) {
|
||||
_moreContentView = [[SuperPlayerSettingsView alloc] initWithFrame:CGRectZero];
|
||||
_moreContentView.controlView = self;
|
||||
_moreContentView.hidden = YES;
|
||||
[self addSubview:_moreContentView];
|
||||
[_moreContentView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.width.mas_equalTo(330);
|
||||
make.height.mas_equalTo(self.mas_height);
|
||||
make.trailing.equalTo(self.mas_trailing).offset(0);
|
||||
make.top.equalTo(self.mas_top).offset(0);
|
||||
}];
|
||||
_moreContentView.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.5];
|
||||
}
|
||||
return _moreContentView;
|
||||
}
|
||||
|
||||
#pragma mark - UIGestureRecognizerDelegate
|
||||
|
||||
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {
|
||||
if ([touch.view isKindOfClass:[UISlider class]]) { // 如果在滑块上点击就不响应pan手势
|
||||
return NO;
|
||||
}
|
||||
return YES;
|
||||
}
|
||||
|
||||
#pragma mark - Public method
|
||||
|
||||
- (void)setHidden:(BOOL)hidden
|
||||
{
|
||||
[super setHidden:hidden];
|
||||
if (hidden) {
|
||||
self.resolutionView.hidden = YES;
|
||||
self.moreContentView.hidden = YES;
|
||||
if (!self.isLockScreen) {
|
||||
self.topImageView.hidden = NO;
|
||||
self.bottomImageView.hidden = NO;
|
||||
}
|
||||
}
|
||||
|
||||
self.lockBtn.hidden = !self.isFullScreen;
|
||||
self.isShowSecondView = NO;
|
||||
self.pointJumpBtn.hidden = YES;
|
||||
}
|
||||
|
||||
/** 重置ControlView */
|
||||
- (void)playerResetControlView {
|
||||
self.videoSlider.value = 0;
|
||||
self.videoSlider.progressView.progress = 0;
|
||||
self.currentTimeLabel.text = @"00:00";
|
||||
self.totalTimeLabel.text = @"00:00";
|
||||
self.playeBtn.hidden = YES;
|
||||
self.resolutionView.hidden = YES;
|
||||
self.backgroundColor = [UIColor clearColor];
|
||||
self.moreBtn.enabled = !self.disableMoreBtn;
|
||||
self.lockBtn.hidden = !self.isFullScreen;
|
||||
|
||||
self.danmakuBtn.enabled = YES;
|
||||
self.captureBtn.enabled = YES;
|
||||
self.backLiveBtn.hidden = YES;
|
||||
}
|
||||
|
||||
- (void)setPointArray:(NSArray *)pointArray
|
||||
{
|
||||
[super setPointArray:pointArray];
|
||||
|
||||
for (PlayerPoint *holder in self.videoSlider.pointArray) {
|
||||
[holder.holder removeFromSuperview];
|
||||
}
|
||||
[self.videoSlider.pointArray removeAllObjects];
|
||||
|
||||
for (SPVideoFrameDescription *p in pointArray) {
|
||||
PlayerPoint *point = [self.videoSlider addPoint:p.where];
|
||||
point.content = p.text;
|
||||
point.timeOffset = p.time;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
- (void)onPlayerPointSelected:(PlayerPoint *)point {
|
||||
NSString *text = [NSString stringWithFormat:@" %@ %@ ", [StrUtils timeFormat:point.timeOffset],
|
||||
point.content];
|
||||
|
||||
[self.pointJumpBtn setTitle:text forState:UIControlStateNormal];
|
||||
[self.pointJumpBtn sizeToFit];
|
||||
CGFloat x = self.videoSlider.mm_x + self.videoSlider.mm_w * point.where - self.pointJumpBtn.mm_h/2;
|
||||
if (x < 0)
|
||||
x = 0;
|
||||
if (x + self.pointJumpBtn.mm_h/2 > ScreenWidth)
|
||||
x = ScreenWidth - self.pointJumpBtn.mm_h/2;
|
||||
self.pointJumpBtn.tag = [self.videoSlider.pointArray indexOfObject:point];
|
||||
self.pointJumpBtn.m_left(x).m_bottom(60);
|
||||
self.pointJumpBtn.hidden = NO;
|
||||
|
||||
[DataReport report:@"player_point" param:nil];
|
||||
}
|
||||
|
||||
- (void)setProgressTime:(NSInteger)currentTime
|
||||
totalTime:(NSInteger)totalTime
|
||||
progressValue:(CGFloat)progress
|
||||
playableValue:(CGFloat)playable {
|
||||
if (!self.isDragging) {
|
||||
// 更新slider
|
||||
self.videoSlider.value = progress;
|
||||
}
|
||||
// 更新当前播放时间
|
||||
self.currentTimeLabel.text = [StrUtils timeFormat:currentTime];
|
||||
// 更新总时间
|
||||
self.totalTimeLabel.text = [StrUtils timeFormat:totalTime];
|
||||
[self.videoSlider.progressView setProgress:playable animated:NO];
|
||||
}
|
||||
|
||||
- (void)resetWithResolutionNames:(NSArray<NSString *> *)resolutionNames
|
||||
currentResolutionIndex:(NSUInteger)currentResolutionIndex
|
||||
isLive:(BOOL)isLive
|
||||
isTimeShifting:(BOOL)isTimeShifting
|
||||
isPlaying:(BOOL)isPlaying
|
||||
{
|
||||
NSAssert(resolutionNames.count == 0 || currentResolutionIndex < resolutionNames.count,
|
||||
@"Invalid argument when reseeting %@", NSStringFromClass(self.class));
|
||||
|
||||
[self setPlayState:isPlaying];
|
||||
self.backLiveBtn.hidden = !isTimeShifting;
|
||||
self.moreContentView.enableSpeedAndMirrorControl = !isLive;
|
||||
|
||||
for (UIView *subview in self.resolutionView.subviews)
|
||||
[subview removeFromSuperview];
|
||||
|
||||
_resolutionArray = resolutionNames;
|
||||
if (_resolutionArray.count > 0) {
|
||||
[self.resolutionBtn setTitle:resolutionNames[currentResolutionIndex]
|
||||
forState:UIControlStateNormal];
|
||||
}
|
||||
UILabel *lable = [UILabel new];
|
||||
lable.text = @"清晰度";
|
||||
lable.textAlignment = NSTextAlignmentCenter;
|
||||
lable.textColor = [UIColor whiteColor];
|
||||
[self.resolutionView addSubview:lable];
|
||||
[lable mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.width.equalTo(self.resolutionView.mas_width);
|
||||
make.height.mas_equalTo(30);
|
||||
make.left.equalTo(self.resolutionView.mas_left);
|
||||
make.top.equalTo(self.resolutionView.mas_top).mas_offset(20);
|
||||
}];
|
||||
|
||||
// 分辨率View上边的Btn
|
||||
for (NSInteger i = 0 ; i < _resolutionArray.count; i++) {
|
||||
UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
|
||||
[btn setTitle:_resolutionArray[i] forState:UIControlStateNormal];
|
||||
[btn setTitleColor:RGBA(252, 89, 81, 1) forState:UIControlStateSelected];
|
||||
[self.resolutionView addSubview:btn];
|
||||
[btn addTarget:self action:@selector(changeResolution:) forControlEvents:UIControlEventTouchUpInside];
|
||||
[btn mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.width.equalTo(self.resolutionView.mas_width);
|
||||
make.height.mas_equalTo(45);
|
||||
make.left.equalTo(self.resolutionView.mas_left);
|
||||
make.centerY.equalTo(self.resolutionView.mas_centerY).offset((i-self.resolutionArray.count/2.0+0.5)*45);
|
||||
}];
|
||||
btn.tag = MODEL_TAG_BEGIN+i;
|
||||
|
||||
if (i == currentResolutionIndex) {
|
||||
btn.selected = YES;
|
||||
btn.backgroundColor = RGBA(34, 30, 24, 1);
|
||||
self.resoultionCurrentBtn = btn;
|
||||
}
|
||||
}
|
||||
if (self.isLive != isLive) {
|
||||
self.isLive = isLive;
|
||||
[self setNeedsLayout];
|
||||
}
|
||||
// 时移的时候不能切清晰度
|
||||
self.resolutionBtn.userInteractionEnabled = !isTimeShifting;
|
||||
}
|
||||
|
||||
/** 播放按钮状态 */
|
||||
- (void)setPlayState:(BOOL)state {
|
||||
self.startBtn.selected = state;
|
||||
}
|
||||
|
||||
- (void)setTitle:(NSString *)title
|
||||
{
|
||||
[super setTitle:title];
|
||||
self.titleLabel.text = title;
|
||||
}
|
||||
|
||||
- (void)hideDanmu {
|
||||
[self setDisableDanmakuBtn:YES];
|
||||
}
|
||||
- (void)hideReplay {
|
||||
[self.repeatBtn setHidden:YES];
|
||||
}
|
||||
|
||||
#pragma clang diagnostic pop
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,40 @@
|
||||
//
|
||||
// SPWeiboControlView.h
|
||||
// SuperPlayer
|
||||
//
|
||||
// Created by annidyfeng on 2018/10/8.
|
||||
//
|
||||
|
||||
#import "SuperPlayerControlView.h"
|
||||
|
||||
@interface SPWeiboControlView : SuperPlayerControlView
|
||||
/** 分辨率的名称 */
|
||||
@property (nonatomic, strong) NSArray<NSString *> *resolutionArray;
|
||||
/** 开始播放按钮 */
|
||||
@property (nonatomic, strong) UIButton *startBtn;
|
||||
/** 当前播放时长label */
|
||||
@property (nonatomic, strong) UILabel *currentTimeLabel;
|
||||
/** 视频总时长label */
|
||||
@property (nonatomic, strong) UILabel *totalTimeLabel;
|
||||
/** 全屏按钮 */
|
||||
@property (nonatomic, strong) UIButton *fullScreenBtn;
|
||||
/** 滑杆 */
|
||||
@property (nonatomic, strong) PlayerSlider *videoSlider;
|
||||
|
||||
@property (nonatomic, strong) UIButton *moreBtn;
|
||||
|
||||
@property (nonatomic, strong) UIButton *backBtn;
|
||||
|
||||
@property (nonatomic, strong) UIButton *muteBtn;
|
||||
|
||||
@property (nonatomic, assign,getter=isFullScreen)BOOL fullScreen;
|
||||
|
||||
/** 切换分辨率按钮 */
|
||||
@property (nonatomic, strong) UIButton *resolutionBtn;
|
||||
@property (nonatomic, strong) UIButton *resoultionCurrentBtn;
|
||||
/** 分辨率的View */
|
||||
@property (nonatomic, strong) UIView *resolutionView;
|
||||
/** 更多设置View */
|
||||
@property (nonatomic, strong) SuperPlayerSettingsView *moreContentView;
|
||||
@property (nonatomic, strong) UIButton *pointJumpBtn;
|
||||
@end
|
||||
@@ -0,0 +1,487 @@
|
||||
//
|
||||
// SPWeiboControlView.m
|
||||
// SuperPlayer
|
||||
//
|
||||
// Created by annidyfeng on 2018/10/8.
|
||||
//
|
||||
|
||||
#import "SPWeiboControlView.h"
|
||||
#import <Masonry/Masonry.h>
|
||||
#import "UIView+Fade.h"
|
||||
#import "UIView+MMLayout.h"
|
||||
#import "StrUtils.h"
|
||||
#import "DataReport.h"
|
||||
#import "SuperPlayer.h"
|
||||
|
||||
@interface SPWeiboControlView() <PlayerSliderDelegate>
|
||||
@property BOOL isLive;
|
||||
@end
|
||||
|
||||
@implementation SPWeiboControlView
|
||||
|
||||
- (instancetype)initWithFrame:(CGRect)frame {
|
||||
self = [super initWithFrame:frame];
|
||||
if (self) {
|
||||
|
||||
[self addSubview:self.startBtn];
|
||||
[self addSubview:self.currentTimeLabel];
|
||||
[self addSubview:self.totalTimeLabel];
|
||||
[self addSubview:self.videoSlider];
|
||||
[self addSubview:self.fullScreenBtn];
|
||||
[self addSubview:self.resolutionBtn];
|
||||
[self addSubview:self.muteBtn];
|
||||
[self addSubview:self.moreBtn];
|
||||
[self addSubview:self.backBtn];
|
||||
|
||||
// 添加子控件的约束
|
||||
[self makeSubViewsConstraints];
|
||||
[self resetControlView];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)makeSubViewsConstraints {
|
||||
[self.startBtn mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.center.equalTo(self);
|
||||
}];
|
||||
[self.currentTimeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.bottom.equalTo(self).offset(-8);
|
||||
make.left.mas_equalTo(@0);
|
||||
make.width.mas_equalTo(@60);
|
||||
}];
|
||||
[self.fullScreenBtn mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.centerY.equalTo(self.currentTimeLabel);
|
||||
make.right.equalTo(self).offset(-12);
|
||||
}];
|
||||
[self.resolutionBtn mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.centerY.equalTo(self.currentTimeLabel);
|
||||
make.right.equalTo(self.fullScreenBtn.mas_left);
|
||||
make.width.mas_equalTo(0);
|
||||
}];
|
||||
[self.totalTimeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.centerY.equalTo(self.currentTimeLabel);
|
||||
make.right.equalTo(self.resolutionBtn.mas_left);
|
||||
make.width.mas_equalTo(@60);
|
||||
}];
|
||||
[self.videoSlider mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.centerY.equalTo(self.currentTimeLabel);
|
||||
make.left.equalTo(self.currentTimeLabel.mas_right);
|
||||
make.right.equalTo(self.totalTimeLabel.mas_left);
|
||||
}];
|
||||
|
||||
[self.backBtn mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.leading.equalTo(self).offset(5);
|
||||
make.top.equalTo(self).offset(3);
|
||||
make.width.mas_equalTo(@60);
|
||||
}];
|
||||
|
||||
[self.moreBtn mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.trailing.equalTo(self).offset(-10);
|
||||
make.centerY.equalTo(self.backBtn);
|
||||
make.width.mas_equalTo(@40);
|
||||
}];
|
||||
[self.muteBtn mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.trailing.equalTo(self.moreBtn.mas_leading).offset(-10);
|
||||
make.centerY.equalTo(self.backBtn);
|
||||
make.width.mas_equalTo(@40);
|
||||
}];
|
||||
}
|
||||
|
||||
|
||||
- (UIButton *)startBtn {
|
||||
if (!_startBtn) {
|
||||
_startBtn = [UIButton buttonWithType:UIButtonTypeCustom];
|
||||
[_startBtn setImage:SuperPlayerImage(@"wb_play") forState:UIControlStateNormal];
|
||||
[_startBtn setImage:SuperPlayerImage(@"wb_pause") forState:UIControlStateSelected];
|
||||
[_startBtn addTarget:self action:@selector(playBtnClick:) forControlEvents:UIControlEventTouchUpInside];
|
||||
}
|
||||
return _startBtn;
|
||||
}
|
||||
|
||||
- (UILabel *)currentTimeLabel {
|
||||
if (!_currentTimeLabel) {
|
||||
_currentTimeLabel = [[UILabel alloc] init];
|
||||
_currentTimeLabel.textColor = [UIColor whiteColor];
|
||||
_currentTimeLabel.font = [UIFont systemFontOfSize:12.0f];
|
||||
_currentTimeLabel.textAlignment = NSTextAlignmentCenter;
|
||||
}
|
||||
return _currentTimeLabel;
|
||||
}
|
||||
|
||||
- (UIButton *)resolutionBtn {
|
||||
if (!_resolutionBtn) {
|
||||
_resolutionBtn = [UIButton buttonWithType:UIButtonTypeCustom];
|
||||
_resolutionBtn.titleLabel.font = [UIFont systemFontOfSize:12];
|
||||
_resolutionBtn.backgroundColor = [UIColor clearColor];
|
||||
[_resolutionBtn addTarget:self action:@selector(resolutionBtnClick:) forControlEvents:UIControlEventTouchUpInside];
|
||||
}
|
||||
return _resolutionBtn;
|
||||
}
|
||||
|
||||
- (PlayerSlider *)videoSlider {
|
||||
if (!_videoSlider) {
|
||||
_videoSlider = [[PlayerSlider alloc] init];
|
||||
[_videoSlider setThumbImage:SuperPlayerImage(@"wb_thumb") forState:UIControlStateNormal];
|
||||
_videoSlider.minimumTrackTintColor = RGBA(223, 223, 223, 1);
|
||||
// slider开始滑动事件
|
||||
[_videoSlider addTarget:self action:@selector(progressSliderTouchBegan:) forControlEvents:UIControlEventTouchDown];
|
||||
// slider滑动中事件
|
||||
[_videoSlider addTarget:self action:@selector(progressSliderValueChanged:) forControlEvents:UIControlEventValueChanged];
|
||||
// slider结束滑动事件
|
||||
[_videoSlider addTarget:self action:@selector(progressSliderTouchEnded:) forControlEvents:UIControlEventTouchUpInside | UIControlEventTouchUpOutside|UIControlEventTouchCancel];
|
||||
_videoSlider.delegate = self;
|
||||
}
|
||||
return _videoSlider;
|
||||
}
|
||||
|
||||
- (UILabel *)totalTimeLabel {
|
||||
if (!_totalTimeLabel) {
|
||||
_totalTimeLabel = [[UILabel alloc] init];
|
||||
_totalTimeLabel.textColor = [UIColor whiteColor];
|
||||
_totalTimeLabel.font = [UIFont systemFontOfSize:12.0f];
|
||||
_totalTimeLabel.textAlignment = NSTextAlignmentCenter;
|
||||
}
|
||||
return _totalTimeLabel;
|
||||
}
|
||||
|
||||
- (UIButton *)fullScreenBtn {
|
||||
if (!_fullScreenBtn) {
|
||||
_fullScreenBtn = [UIButton buttonWithType:UIButtonTypeCustom];
|
||||
[_fullScreenBtn setImage:SuperPlayerImage(@"wb_fullscreen") forState:UIControlStateNormal];
|
||||
[_fullScreenBtn setImage:SuperPlayerImage(@"wb_fullscreen_back") forState:UIControlStateSelected];
|
||||
[_fullScreenBtn addTarget:self action:@selector(fullScreenBtnClick:) forControlEvents:UIControlEventTouchUpInside];
|
||||
}
|
||||
return _fullScreenBtn;
|
||||
}
|
||||
|
||||
- (UIButton *)backBtn {
|
||||
if (!_backBtn) {
|
||||
_backBtn = [UIButton buttonWithType:UIButtonTypeCustom];
|
||||
[_backBtn setImage:SuperPlayerImage(@"wb_back") forState:UIControlStateNormal];
|
||||
[_backBtn addTarget:self action:@selector(fullScreenBtnClick:) forControlEvents:UIControlEventTouchUpInside];
|
||||
}
|
||||
return _backBtn;
|
||||
}
|
||||
- (UIButton *)moreBtn {
|
||||
if (!_moreBtn) {
|
||||
_moreBtn = [UIButton buttonWithType:UIButtonTypeCustom];
|
||||
[_moreBtn setImage:SuperPlayerImage(@"wb_more") forState:UIControlStateNormal];
|
||||
[_moreBtn addTarget:self action:@selector(moreBtnClick:) forControlEvents:UIControlEventTouchUpInside];
|
||||
}
|
||||
return _moreBtn;
|
||||
}
|
||||
- (UIButton *)muteBtn {
|
||||
if (!_muteBtn) {
|
||||
_muteBtn = [UIButton buttonWithType:UIButtonTypeCustom];
|
||||
[_muteBtn setImage:SuperPlayerImage(@"wb_volume_on") forState:UIControlStateNormal];
|
||||
[_muteBtn setImage:SuperPlayerImage(@"wb_volume_off") forState:UIControlStateSelected];
|
||||
[_muteBtn addTarget:self action:@selector(muteBtnClick:) forControlEvents:UIControlEventTouchUpInside];
|
||||
}
|
||||
return _muteBtn;
|
||||
}
|
||||
|
||||
- (UIView *)resolutionView {
|
||||
if (!_resolutionView) {
|
||||
// 添加分辨率按钮和分辨率下拉列表
|
||||
|
||||
_resolutionView = [[UIView alloc] initWithFrame:CGRectZero];
|
||||
_resolutionView.hidden = YES;
|
||||
[self addSubview:_resolutionView];
|
||||
[_resolutionView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.width.mas_equalTo(330);
|
||||
make.height.mas_equalTo(self.mas_height);
|
||||
make.trailing.equalTo(self.mas_trailing).offset(0);
|
||||
make.top.equalTo(self.mas_top).offset(0);
|
||||
}];
|
||||
|
||||
_resolutionView.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.5];
|
||||
}
|
||||
return _resolutionView;
|
||||
}
|
||||
|
||||
- (SuperPlayerSettingsView *)moreContentView {
|
||||
if (!_moreContentView) {
|
||||
_moreContentView = [[SuperPlayerSettingsView alloc] initWithFrame:CGRectZero];
|
||||
_moreContentView.controlView = self;
|
||||
[self addSubview:_moreContentView];
|
||||
[_moreContentView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.width.mas_equalTo(330);
|
||||
make.height.mas_equalTo(self.mas_height);
|
||||
make.trailing.equalTo(self.mas_trailing).offset(0);
|
||||
make.top.equalTo(self.mas_top).offset(0);
|
||||
}];
|
||||
_moreContentView.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.5];
|
||||
}
|
||||
return _moreContentView;
|
||||
}
|
||||
|
||||
- (void)playBtnClick:(UIButton *)sender {
|
||||
sender.selected = !sender.selected;
|
||||
if (sender.selected) {
|
||||
[self.delegate controlViewPlay:self];
|
||||
} else {
|
||||
[self.delegate controlViewPause:self];
|
||||
}
|
||||
[self cancelFadeOut];
|
||||
}
|
||||
|
||||
- (void)fullScreenBtnClick:(UIButton *)sender {
|
||||
sender.selected = !sender.selected;
|
||||
[self.delegate controlViewChangeScreen:self withFullScreen:sender.selected];
|
||||
}
|
||||
|
||||
- (void)progressSliderTouchBegan:(UISlider *)sender {
|
||||
self.isDragging = YES;
|
||||
self.startBtn.hidden = YES; // 播放按钮挡住了fastView
|
||||
[self cancelFadeOut];
|
||||
}
|
||||
|
||||
- (void)progressSliderValueChanged:(UISlider *)sender {
|
||||
if (self.maxPlayableRatio > 0 && sender.value * self.maxPlayableRatio) {
|
||||
sender.value = self.maxPlayableRatio;
|
||||
}
|
||||
[self.delegate controlViewPreview:self where:sender.value];
|
||||
}
|
||||
|
||||
- (void)progressSliderTouchEnded:(UISlider *)sender {
|
||||
[self.delegate controlViewSeek:self where:sender.value];
|
||||
self.isDragging = NO;
|
||||
self.startBtn.hidden = NO;
|
||||
[self cancelFadeOut];
|
||||
}
|
||||
|
||||
- (void)setProgressTime:(NSInteger)currentTime totalTime:(NSInteger)totalTime
|
||||
progressValue:(CGFloat)progress playableValue:(CGFloat)playable;
|
||||
{
|
||||
if (!self.isDragging) {
|
||||
// 更新slider
|
||||
self.videoSlider.value = progress;
|
||||
// 更新当前播放时间
|
||||
self.currentTimeLabel.text = [StrUtils timeFormat:currentTime];
|
||||
}
|
||||
// 更新总时间
|
||||
self.totalTimeLabel.text = [StrUtils timeFormat:totalTime];
|
||||
[self.videoSlider.progressView setProgress:playable animated:NO];
|
||||
}
|
||||
|
||||
- (void)muteBtnClick:(UIButton *)sender
|
||||
{
|
||||
sender.selected = self.playerConfig.mute = !self.playerConfig.mute;
|
||||
[self.delegate controlViewConfigUpdate:self withReload:NO];
|
||||
[self fadeOut:3];
|
||||
}
|
||||
|
||||
|
||||
/** 重置ControlView */
|
||||
- (void)resetControlView {
|
||||
self.videoSlider.value = 0;
|
||||
self.videoSlider.progressView.progress = 0;
|
||||
self.currentTimeLabel.text = @"00:00";
|
||||
self.totalTimeLabel.text = @"00:00";
|
||||
self.moreContentView.hidden = YES;
|
||||
}
|
||||
|
||||
- (void)setHidden:(BOOL)hidden
|
||||
{
|
||||
[super setHidden:hidden];
|
||||
|
||||
for (UIView *view in self.subviews) {
|
||||
if (view != self.resolutionView && view != self.moreContentView) {
|
||||
if (!self.isFullScreen && (view == self.backBtn || view == self.moreBtn || view == self.muteBtn))
|
||||
view.hidden = YES;
|
||||
else
|
||||
view.hidden = NO;
|
||||
} else {
|
||||
view.hidden = YES;
|
||||
}
|
||||
}
|
||||
self.isShowSecondView = NO;
|
||||
self.pointJumpBtn.hidden = YES;
|
||||
}
|
||||
|
||||
/** 播放按钮状态 */
|
||||
- (void)setPlayState:(BOOL)isPlay {
|
||||
self.startBtn.selected = isPlay;
|
||||
}
|
||||
|
||||
- (void)resolutionBtnClick:(UIButton *)sender {
|
||||
for (UIView *view in self.subviews) {
|
||||
view.hidden = YES;
|
||||
}
|
||||
|
||||
// 显示分辨率View
|
||||
self.resolutionView.hidden = NO;
|
||||
[DataReport report:@"change_resolution" param:nil];
|
||||
|
||||
[self cancelFadeOut];
|
||||
self.isShowSecondView = YES;
|
||||
}
|
||||
|
||||
- (void)moreBtnClick:(UIButton *)sender {
|
||||
for (UIView *view in self.subviews) {
|
||||
view.hidden = YES;
|
||||
}
|
||||
|
||||
self.moreContentView.playerConfig = self.playerConfig;
|
||||
self.moreContentView.enableSpeedAndMirrorControl = !self.isLive;
|
||||
[self.moreContentView update];
|
||||
self.moreContentView.hidden = NO;
|
||||
|
||||
[self cancelFadeOut];
|
||||
self.isShowSecondView = YES;
|
||||
}
|
||||
|
||||
- (void)resetWithResolutionNames:(NSArray<NSString *> *)resolutionNames
|
||||
currentResolutionIndex:(NSUInteger)currentResolutionIndex
|
||||
isLive:(BOOL)isLive
|
||||
isTimeShifting:(BOOL)isTimeShifting
|
||||
isPlaying:(BOOL)isPlaying
|
||||
{
|
||||
[self setPlayState:isPlaying];
|
||||
|
||||
_resolutionArray = resolutionNames;
|
||||
NSAssert(currentResolutionIndex < resolutionNames.count,
|
||||
@"Invalid argument when reseeting %@", NSStringFromClass(self.class));
|
||||
if (resolutionNames.count > 0) {
|
||||
[self.resolutionBtn setTitle:resolutionNames[currentResolutionIndex]
|
||||
forState:UIControlStateNormal];
|
||||
}
|
||||
for (UIView *subview in self.resolutionView.subviews)
|
||||
[subview removeFromSuperview];
|
||||
|
||||
UILabel *lable = [UILabel new];
|
||||
lable.text = @"清晰度";
|
||||
lable.textAlignment = NSTextAlignmentCenter;
|
||||
lable.textColor = [UIColor whiteColor];
|
||||
[self.resolutionView addSubview:lable];
|
||||
[lable mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.width.equalTo(self.resolutionView.mas_width);
|
||||
make.height.mas_equalTo(30);
|
||||
make.left.equalTo(self.resolutionView.mas_left);
|
||||
make.top.equalTo(self.resolutionView.mas_top).mas_offset(20);
|
||||
}];
|
||||
|
||||
// 分辨率View上边的Btn
|
||||
for (NSInteger i = 0 ; i < _resolutionArray.count; i++) {
|
||||
UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
|
||||
[btn setTitle:_resolutionArray[i] forState:UIControlStateNormal];
|
||||
[btn setTitleColor:RGBA(252, 89, 81, 1) forState:UIControlStateSelected];
|
||||
[self.resolutionView addSubview:btn];
|
||||
[btn addTarget:self action:@selector(changeResolution:) forControlEvents:UIControlEventTouchUpInside];
|
||||
[btn mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.width.equalTo(self.resolutionView.mas_width);
|
||||
make.height.mas_equalTo(45);
|
||||
make.left.equalTo(self.resolutionView.mas_left);
|
||||
make.centerY.equalTo(self.resolutionView.mas_centerY).offset((i-self.resolutionArray.count/2.0+0.5)*45);
|
||||
}];
|
||||
|
||||
if (i == currentResolutionIndex) {
|
||||
btn.selected = YES;
|
||||
btn.backgroundColor = RGBA(34, 30, 24, 1);
|
||||
self.resoultionCurrentBtn = btn;
|
||||
}
|
||||
}
|
||||
if (self.isLive != isLive) {
|
||||
self.isLive = isLive;
|
||||
[self setNeedsLayout];
|
||||
}
|
||||
// 时移的时候不能切清晰度
|
||||
self.resolutionBtn.userInteractionEnabled = !isTimeShifting;
|
||||
}
|
||||
|
||||
/**
|
||||
* 点击切换分别率按钮
|
||||
*/
|
||||
- (void)changeResolution:(UIButton *)sender {
|
||||
self.resoultionCurrentBtn.selected = NO;
|
||||
self.resoultionCurrentBtn.backgroundColor = [UIColor clearColor];
|
||||
self.resoultionCurrentBtn = sender;
|
||||
self.resoultionCurrentBtn.selected = YES;
|
||||
self.resoultionCurrentBtn.backgroundColor = RGBA(34, 30, 24, 1);
|
||||
|
||||
// topImageView上的按钮的文字
|
||||
[self.resolutionBtn setTitle:sender.titleLabel.text forState:UIControlStateNormal];
|
||||
[self.delegate controlViewSwitch:self withDefinition:sender.titleLabel.text];
|
||||
}
|
||||
|
||||
- (void)setOrientationLandscapeConstraint {
|
||||
self.fullScreen = YES;
|
||||
self.fullScreenBtn.selected = YES;
|
||||
self.moreBtn.hidden = NO;
|
||||
self.backBtn.hidden = NO;
|
||||
self.muteBtn.hidden = NO;
|
||||
[self.resolutionBtn mas_updateConstraints:^(MASConstraintMaker *make) {
|
||||
make.width.mas_equalTo(@60);
|
||||
}];
|
||||
|
||||
self.videoSlider.hiddenPoints = NO;
|
||||
}
|
||||
|
||||
- (void)setOrientationPortraitConstraint {
|
||||
self.fullScreen = NO;
|
||||
self.fullScreenBtn.selected = NO;
|
||||
self.moreBtn.hidden = YES;
|
||||
self.backBtn.hidden = YES;
|
||||
self.muteBtn.hidden = YES;
|
||||
[self.resolutionBtn mas_updateConstraints:^(MASConstraintMaker *make) {
|
||||
make.width.mas_equalTo(@0);
|
||||
}];
|
||||
|
||||
|
||||
self.videoSlider.hiddenPoints = YES;
|
||||
self.pointJumpBtn.hidden = YES;
|
||||
}
|
||||
|
||||
- (void)setPointArray:(NSArray *)pointArray
|
||||
{
|
||||
[super setPointArray:pointArray];
|
||||
|
||||
for (PlayerPoint *holder in self.videoSlider.pointArray) {
|
||||
[holder.holder removeFromSuperview];
|
||||
}
|
||||
[self.videoSlider.pointArray removeAllObjects];
|
||||
|
||||
for (SPVideoFrameDescription *p in pointArray) {
|
||||
PlayerPoint *point = [self.videoSlider addPoint:p.where];
|
||||
point.content = p.text;
|
||||
point.timeOffset = p.time;
|
||||
}
|
||||
}
|
||||
|
||||
- (UIButton *)pointJumpBtn {
|
||||
if (!_pointJumpBtn) {
|
||||
_pointJumpBtn = [UIButton buttonWithType:UIButtonTypeCustom];
|
||||
UIImage *image = SuperPlayerImage(@"copywright_bg");
|
||||
UIImage *resizableImage = [image resizableImageWithCapInsets:UIEdgeInsetsMake(0, 20, 0, 20) resizingMode:UIImageResizingModeStretch];
|
||||
[_pointJumpBtn setBackgroundImage:resizableImage forState:UIControlStateNormal];
|
||||
_pointJumpBtn.titleLabel.font = [UIFont systemFontOfSize:14];
|
||||
[_pointJumpBtn addTarget:self action:@selector(pointJumpClick:) forControlEvents:UIControlEventTouchUpInside];
|
||||
[self addSubview:_pointJumpBtn];
|
||||
}
|
||||
return _pointJumpBtn;
|
||||
}
|
||||
|
||||
- (void)pointJumpClick:(UIButton *)sender {
|
||||
PlayerPoint *point = [self.videoSlider.pointArray objectAtIndex:self.pointJumpBtn.tag];
|
||||
[self.delegate controlViewSeek:self where:point.where];
|
||||
[self fadeOut:0.1];
|
||||
}
|
||||
|
||||
- (void)onPlayerPointSelected:(PlayerPoint *)point {
|
||||
NSString *text = [NSString stringWithFormat:@" %@ %@ ", [StrUtils timeFormat:point.timeOffset],
|
||||
point.content];
|
||||
|
||||
[self.pointJumpBtn setTitle:text forState:UIControlStateNormal];
|
||||
[self.pointJumpBtn sizeToFit];
|
||||
CGFloat x = self.videoSlider.mm_x + self.videoSlider.mm_w * point.where - self.pointJumpBtn.mm_w/2;
|
||||
if (x < 0)
|
||||
x = 0;
|
||||
if (x + self.pointJumpBtn.mm_w/2 > ScreenWidth)
|
||||
x = ScreenWidth - self.pointJumpBtn.mm_w/2;
|
||||
self.pointJumpBtn.tag = [self.videoSlider.pointArray indexOfObject:point];
|
||||
self.pointJumpBtn.m_left(x).m_bottom(60);
|
||||
self.pointJumpBtn.hidden = NO;
|
||||
|
||||
[DataReport report:@"player_point" param:nil];
|
||||
}
|
||||
@end
|
||||
@@ -0,0 +1,12 @@
|
||||
//
|
||||
// SPWithoutControlView.h
|
||||
// SuperPlayer
|
||||
//
|
||||
// Created by annidyfeng on 2021/4/15.
|
||||
//
|
||||
|
||||
#import "SuperPlayerControlView.h"
|
||||
|
||||
@interface SPWithoutControlView : SuperPlayerControlView
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,39 @@
|
||||
#import "SuperPlayerControlView.h"
|
||||
#import <AVFoundation/AVFoundation.h>
|
||||
#import <MediaPlayer/MediaPlayer.h>
|
||||
|
||||
#import "SuperPlayerSettingsView.h"
|
||||
#import "DataReport.h"
|
||||
#import "SuperPlayerFastView.h"
|
||||
#import "PlayerSlider.h"
|
||||
#import "UIView+MMLayout.h"
|
||||
#import "SuperPlayerView+Private.h"
|
||||
#import "StrUtils.h"
|
||||
#import "SPWithoutControlView.h"
|
||||
#import "UIView+Fade.h"
|
||||
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored"-Wdeprecated-declarations"
|
||||
|
||||
#define MODEL_TAG_BEGIN 20
|
||||
#define BOTTOM_IMAGE_VIEW_HEIGHT 50
|
||||
|
||||
@interface SPWithoutControlView () <UIGestureRecognizerDelegate, PlayerSliderDelegate>
|
||||
@property BOOL isLive;
|
||||
@end
|
||||
|
||||
@implementation SPWithoutControlView
|
||||
|
||||
- (instancetype)initWithFrame:(CGRect)frame {
|
||||
self = [super initWithFrame:frame];
|
||||
if (self) {
|
||||
// skip
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)dealloc {
|
||||
[[NSNotificationCenter defaultCenter] removeObserver:self];
|
||||
}
|
||||
|
||||
@end
|
||||
Reference in New Issue
Block a user