Skip to content

Commit

Permalink
Added a lightweight control layer.
Browse files Browse the repository at this point in the history
  • Loading branch information
changsanjiang committed Mar 21, 2018
1 parent c6b5b30 commit 8cf411c
Show file tree
Hide file tree
Showing 50 changed files with 2,164 additions and 248 deletions.
2 changes: 1 addition & 1 deletion SJVideoPlayer.podspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Pod::Spec.new do |s|
s.name = 'SJVideoPlayer'
s.version = '2.0.3.7'
s.version = '2.0.3.8'
s.summary = 'video player.'
s.description = 'https://github.com/changsanjiang/SJVideoPlayer/blob/master/README.md'
s.homepage = 'https://github.com/changsanjiang/SJVideoPlayer'
Expand Down
Binary file modified SJVideoPlayer/.DS_Store
Binary file not shown.
12 changes: 6 additions & 6 deletions SJVideoPlayer/ControlView/SJVideoPlayerFilmEditingControlView.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ typedef NS_ENUM(NSUInteger, SJVideoPlayerFilmEditingViewTag) {
SJVideoPlayerFilmEditingViewTag_Export,
};

typedef NS_ENUM(NSUInteger, SJVideoPlayerFilmEditingRecrodStatus) {
SJVideoPlayerFilmEditingRecrodStatus_Unknown,
SJVideoPlayerFilmEditingRecrodStatus_Recording,
SJVideoPlayerFilmEditingRecrodStatus_Finished,
SJVideoPlayerFilmEditingRecrodStatus_Paused,
typedef NS_ENUM(NSUInteger, SJVideoPlayerFilmEditingStatus) {
SJVideoPlayerFilmEditingStatus_Unknown,
SJVideoPlayerFilmEditingStatus_Recording,
SJVideoPlayerFilmEditingStatus_Finished, // screenshot finished || record finished
SJVideoPlayerFilmEditingStatus_Paused,
};

@interface SJVideoPlayerFilmEditingControlView : UIView
Expand All @@ -38,7 +38,7 @@ typedef NS_ENUM(NSUInteger, SJVideoPlayerFilmEditingRecrodStatus) {


#pragma mark - record
@property (nonatomic, readonly) SJVideoPlayerFilmEditingRecrodStatus recordStatus;
@property (nonatomic, readonly) SJVideoPlayerFilmEditingStatus recordStatus;
- (void)pauseRecording;
- (void)resumeRecording;
- (void)completeRecording;
Expand Down
12 changes: 6 additions & 6 deletions SJVideoPlayer/ControlView/SJVideoPlayerFilmEditingControlView.m
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ @interface SJVideoPlayerFilmEditingControlView ()
@property (nonatomic, strong, readonly) SJVideoPlayerFilmEditingRecordView *recordView;
@property (nonatomic, strong, readonly) UITapGestureRecognizer *tapGR;
@property (nonatomic, weak, readwrite) SJFilmEditingResultUploader *uploader;
@property (nonatomic, readwrite) SJVideoPlayerFilmEditingRecrodStatus recordStatus;
@property (nonatomic, readwrite) SJVideoPlayerFilmEditingStatus recordStatus;

@end
NS_ASSUME_NONNULL_END
Expand Down Expand Up @@ -56,13 +56,13 @@ - (void)clickedBtn:(UIButton *)btn {
switch ( btn.tag ) {
// screenshot
case SJVideoPlayerFilmEditingViewTag_Screenshot: {
_recordStatus = SJVideoPlayerFilmEditingRecrodStatus_Unknown;
_recordStatus = SJVideoPlayerFilmEditingStatus_Finished;
[self _showResultWithType:SJVideoPlayerFilmEditingResultViewType_Screenshot];
}
break;
// export
case SJVideoPlayerFilmEditingViewTag_Export: {
_recordStatus = SJVideoPlayerFilmEditingRecrodStatus_Recording;
_recordStatus = SJVideoPlayerFilmEditingStatus_Recording;
if ( _startRecordingExeBlock ) _startRecordingExeBlock(self);
self.recordView.tipsText = _recordTipsText;
_recordView.waitingForRecordingTipsText = _waitingForRecordingTipsText;
Expand All @@ -84,17 +84,17 @@ - (void)clickedBtn:(UIButton *)btn {
}

- (void)pauseRecording {
_recordStatus = SJVideoPlayerFilmEditingRecrodStatus_Paused;
_recordStatus = SJVideoPlayerFilmEditingStatus_Paused;
[_recordView pause];
}

- (void)resumeRecording {
_recordStatus = SJVideoPlayerFilmEditingRecrodStatus_Recording;
_recordStatus = SJVideoPlayerFilmEditingStatus_Recording;
[_recordView resume];
}

- (void)completeRecording {
_recordStatus = SJVideoPlayerFilmEditingRecrodStatus_Finished;
_recordStatus = SJVideoPlayerFilmEditingStatus_Finished;
[_recordView stop];
[self _showResultWithType:SJVideoPlayerFilmEditingResultViewType_Video];
}
Expand Down
5 changes: 3 additions & 2 deletions SJVideoPlayer/ControlView/UIView+SJControlAdd.m
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,16 @@ - (void)__changeState:(BOOL)show {
self.alpha = 0.001;
}
}

self.appearState = show;

if ( show ) {
if ( self.appearExeBlock ) self.appearExeBlock(self);
}
else {
if ( self.disappearExeBlock ) self.disappearExeBlock(self);
}

self.appearState = show;

}

@end
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
//
// SJLightweightBottomControlView.h
// SJVideoPlayerProject
//
// Created by BlueDancer on 2018/3/21.
// Copyright © 2018年 SanJiang. All rights reserved.
//

#import <UIKit/UIKit.h>

NS_ASSUME_NONNULL_BEGIN
typedef NS_ENUM(NSUInteger, SJLightweightBottomControlViewTag) {
SJLightweightBottomControlViewTag_Play,
SJLightweightBottomControlViewTag_Pause,
SJLightweightBottomControlViewTag_Full,
};

@protocol SJLightweightBottomControlViewDelegate;

@interface SJLightweightBottomControlView : UIView

@property (nonatomic, weak, readwrite, nullable) id<SJLightweightBottomControlViewDelegate> delegate;

@property (nonatomic) BOOL isFullscreen;

@property (nonatomic) float progress;

@property (nonatomic) float bufferProgress;

@property (nonatomic, getter=isStopped) BOOL stopped;

- (void)setCurrentTimeStr:(NSString *)currentTimeStr;
- (void)setCurrentTimeStr:(NSString *)currentTimeStr totalTimeStr:(NSString *)totalTimeStr;

@end

@protocol SJLightweightBottomControlViewDelegate <NSObject>

@optional
- (void)bottomControlView:(SJLightweightBottomControlView *)bottomControlView clickedViewTag:(SJLightweightBottomControlViewTag)tag;

- (void)sliderWillBeginDraggingForBottomView:(SJLightweightBottomControlView *)view;

- (void)bottomView:(SJLightweightBottomControlView *)view sliderDidDrag:(CGFloat)value;

- (void)sliderDidEndDraggingForBottomView:(SJLightweightBottomControlView *)view;

@end
NS_ASSUME_NONNULL_END
243 changes: 243 additions & 0 deletions SJVideoPlayer/LightweightControlView/SJLightweightBottomControlView.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,243 @@
//
// SJLightweightBottomControlView.m
// SJVideoPlayerProject
//
// Created by BlueDancer on 2018/3/21.
// Copyright © 2018年 SanJiang. All rights reserved.
//

#import "SJLightweightBottomControlView.h"
#import <SJSlider/SJSlider.h>
#import <SJUIFactory/SJUIFactory.h>
#import <Masonry/Masonry.h>
#import "SJVideoPlayerControlMaskView.h"
#import "UIView+SJVideoPlayerSetting.h"

@interface SJLightweightBottomControlView ()<SJSliderDelegate>

@property (nonatomic, strong, readonly) UIButton *playBtn;
@property (nonatomic, strong, readonly) UIButton *pauseBtn;
@property (nonatomic, strong, readonly) UILabel *currentTimeLabel;
@property (nonatomic, strong, readonly) UILabel *separateLabel;
@property (nonatomic, strong, readonly) UILabel *durationTimeLabel;
@property (nonatomic, strong, readonly) SJSlider *progressSlider;
@property (nonatomic, strong, readonly) UIButton *fullBtn;

@end

@implementation SJLightweightBottomControlView
@synthesize separateLabel = _separateLabel;
@synthesize durationTimeLabel = _durationTimeLabel;
@synthesize playBtn = _playBtn;
@synthesize pauseBtn = _pauseBtn;
@synthesize currentTimeLabel = _currentTimeLabel;
@synthesize progressSlider = _progressSlider;
@synthesize fullBtn = _fullBtn;

- (instancetype)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if ( !self ) return nil;
[self _bottomSetupView];
[self _bottomSettingHelper];
[self setStopped:YES];
return self;
}

- (CGSize)intrinsicContentSize {
if ( _isFullscreen ) {
if ( SJ_is_iPhoneX() ) return CGSizeMake(SJScreen_Max(), 60);
else return CGSizeMake(SJScreen_Max(), 49);
}

return CGSizeMake(SJScreen_Min(), 49);
}

- (void)setIsFullscreen:(BOOL)isFullscreen {
_isFullscreen = isFullscreen;
[self invalidateIntrinsicContentSize];
}

- (void)setStopped:(BOOL)stopped {
_stopped = stopped;
[UIView animateWithDuration:0.3 animations:^{
if ( stopped ) {
self.playBtn.alpha = 1;
self.pauseBtn.alpha = 0.001;
}
else {
self.playBtn.alpha = 0.001;
self.pauseBtn.alpha = 1;
}
}];
}

- (void)setCurrentTimeStr:(NSString *)currentTimeStr {
self.currentTimeLabel.text = currentTimeStr;
}

- (void)setCurrentTimeStr:(NSString *)currentTimeStr totalTimeStr:(NSString *)totalTimeStr {
self.currentTimeLabel.text = currentTimeStr;
self.durationTimeLabel.text = totalTimeStr;
}

- (void)clickedBtn:(UIButton *)btn {
if ( ![_delegate respondsToSelector:@selector(bottomControlView:clickedViewTag:)] ) return;
[_delegate bottomControlView:self clickedViewTag:btn.tag];
}

- (void)setProgress:(float)progress {
if ( self.progressSlider.isDragging ) return;
self.progressSlider.value = progress;
}

- (float)progress {
return self.progressSlider.value;
}

- (void)setBufferProgress:(float)bufferProgress {
self.progressSlider.bufferProgress = bufferProgress;
}

- (float)bufferProgress {
return self.progressSlider.bufferProgress;
}

#pragma mark -

- (void)_bottomSetupView {
[self addSubview:self.playBtn];
[self addSubview:self.pauseBtn];
[self addSubview:self.currentTimeLabel];
[self addSubview:self.separateLabel];
[self addSubview:self.durationTimeLabel];
[self addSubview:self.progressSlider];
[self addSubview:self.fullBtn];

[_playBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.leading.offset(0);
make.size.offset(49);
}];

[_pauseBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(_playBtn);
}];

[_currentTimeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerY.equalTo(_separateLabel);
make.leading.equalTo(_playBtn.mas_trailing).offset(-8);
make.width.equalTo(_durationTimeLabel).offset(8);
}];

[_separateLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerY.equalTo(_playBtn);
make.leading.equalTo(_currentTimeLabel.mas_trailing);
}];

[_durationTimeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.leading.equalTo(_separateLabel.mas_trailing);
make.centerY.equalTo(_separateLabel);
}];

[_progressSlider mas_makeConstraints:^(MASConstraintMaker *make) {
make.leading.equalTo(_durationTimeLabel.mas_trailing).offset(12);
make.height.centerY.equalTo(_playBtn);
make.trailing.equalTo(_fullBtn.mas_leading).offset(-8);
}];

[_fullBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.size.equalTo(_playBtn);
make.centerY.equalTo(_playBtn);
make.trailing.offset(0);
}];

[SJUIFactory boundaryProtectedWithView:_fullBtn];
[SJUIFactory boundaryProtectedWithView:_playBtn];
[SJUIFactory boundaryProtectedWithView:_durationTimeLabel];
[SJUIFactory boundaryProtectedWithView:_progressSlider];
}

- (UIButton *)playBtn {
if ( _playBtn ) return _playBtn;
_playBtn = [SJUIButtonFactory buttonWithImageName:nil target:self sel:@selector(clickedBtn:) tag:SJLightweightBottomControlViewTag_Play];
return _playBtn;
}

- (UIButton *)pauseBtn {
if ( _pauseBtn ) return _pauseBtn;
_pauseBtn = [SJUIButtonFactory buttonWithImageName:nil target:self sel:@selector(clickedBtn:) tag:SJLightweightBottomControlViewTag_Pause];
return _pauseBtn;
}

- (SJSlider *)progressSlider {
if ( _progressSlider ) return _progressSlider;
_progressSlider = [SJSlider new];
_progressSlider.enableBufferProgress = YES;
_progressSlider.delegate = self;
return _progressSlider;
}

- (void)sliderWillBeginDragging:(SJSlider *)slider {
if ( [self.delegate respondsToSelector:@selector(sliderWillBeginDraggingForBottomView:)] ) {
[self.delegate sliderWillBeginDraggingForBottomView:self];
}
}

- (void)sliderDidDrag:(SJSlider *)slider {
if ( [self.delegate respondsToSelector:@selector(bottomView:sliderDidDrag:)] ) {
[self.delegate bottomView:self sliderDidDrag:slider.value];
}
}

- (void)sliderDidEndDragging:(SJSlider *)slider {
if ( [self.delegate respondsToSelector:@selector(sliderDidEndDraggingForBottomView:)] ) {
[self.delegate sliderDidEndDraggingForBottomView:self];
}
}

- (UIButton *)fullBtn {
if ( _fullBtn ) return _fullBtn;
_fullBtn = [SJUIButtonFactory buttonWithImageName:nil target:self sel:@selector(clickedBtn:) tag:SJLightweightBottomControlViewTag_Full];
return _fullBtn;
}

- (UILabel *)separateLabel {
if ( _separateLabel ) return _separateLabel;
_separateLabel = [SJUILabelFactory labelWithText:@"/" textColor:[UIColor whiteColor] alignment:NSTextAlignmentCenter font:[UIFont systemFontOfSize:10]];
return _separateLabel;
}

- (UILabel *)durationTimeLabel {
if ( _durationTimeLabel ) return _durationTimeLabel;
_durationTimeLabel = [SJUILabelFactory labelWithText:@"00:00" textColor:[UIColor whiteColor] alignment:NSTextAlignmentLeft font:[UIFont systemFontOfSize:self.separateLabel.font.pointSize + 1]];
return _durationTimeLabel;
}

- (UILabel *)currentTimeLabel {
if ( _currentTimeLabel ) return _currentTimeLabel;
_currentTimeLabel = [SJUILabelFactory labelWithText:@"00:00" textColor:[UIColor whiteColor] alignment:NSTextAlignmentRight font:[UIFont systemFontOfSize:self.separateLabel.font.pointSize + 1]];
return _currentTimeLabel;
}

#pragma mark -
- (void)_bottomSettingHelper {
__weak typeof(self) _self = self;
self.settingRecroder = [[SJVideoPlayerControlSettingRecorder alloc] initWithSettings:^(SJVideoPlayerSettings * _Nonnull setting) {
__strong typeof(_self) self = _self;
if ( !self ) return;
[self.playBtn setImage:setting.playBtnImage forState:UIControlStateNormal];
[self.pauseBtn setImage:setting.pauseBtnImage forState:UIControlStateNormal];
[self.fullBtn setImage:setting.fullBtnImage forState:UIControlStateNormal];
self.progressSlider.traceImageView.backgroundColor = setting.progress_traceColor;
self.progressSlider.trackImageView.backgroundColor = setting.progress_trackColor;
if ( setting.progress_thumbImage ) {
self.progressSlider.thumbImageView.image = setting.progress_thumbImage;
}
else if ( setting.progress_thumbSize ) {
[self.progressSlider setThumbCornerRadius:setting.progress_thumbSize * 0.5 size:CGSizeMake(setting.progress_thumbSize, setting.progress_thumbSize) thumbBackgroundColor:setting.progress_thumbColor];
}
self.progressSlider.bufferProgressColor = setting.progress_bufferColor;
self.progressSlider.trackHeight = setting.progress_traceHeight;
}];
}
@end

Loading

0 comments on commit 8cf411c

Please sign in to comment.