Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

新增封面圖片,新增旋轉控制,改善 Slider 圖片清晰度 #13

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CLPlayer/CLPlayerMaskView.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@
@property (nonatomic,strong) CLSlider *slider;
/**加载失败按钮*/
@property (nonatomic,strong) UIButton *failButton;
/**封面圖片*/
@property (nonatomic,strong) UIImageView *coverImageView;
/**代理人*/
@property (nonatomic,weak) id<CLPlayerMaskViewDelegate> delegate;
/**进度条背景颜色*/
Expand Down
14 changes: 14 additions & 0 deletions CLPlayer/CLPlayerMaskView.m
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ -(instancetype)initWithFrame:(CGRect)frame{
return self;
}
- (void)initViews{
[self addSubview:self.coverImageView];
[self addSubview:self.topToolBar];
[self addSubview:self.bottomToolBar];
[self addSubview:self.activity];
Expand Down Expand Up @@ -55,6 +56,10 @@ - (void)makeConstraints{
make.left.right.bottom.equalTo(self);
make.height.mas_equalTo(ToolBarHeight);
}];
//封面圖片
[self.coverImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.left.right.bottom.equalTo(self);
}];
//转子
[self.activity mas_makeConstraints:^(MASConstraintMaker *make) {
make.center.equalTo(self);
Expand Down Expand Up @@ -235,6 +240,15 @@ - (UIButton *) failButton
}
return _failButton;
}
//封面圖片
- (UIImageView *)coverImageView {
if (_coverImageView == nil){
_coverImageView = [[UIImageView alloc] init];
_coverImageView.backgroundColor = [UIColor blackColor];
_coverImageView.contentMode = UIViewContentModeScaleAspectFit;
}
return _coverImageView;
}
#pragma mark - 按钮点击事件
//返回按钮
- (void)backButtonAction:(UIButton *)button{
Expand Down
4 changes: 4 additions & 0 deletions CLPlayer/CLPlayerView.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ typedef void(^BeyondBlock)();
@property (nonatomic, assign) BOOL repeatPlay;
/**是否支持横屏,默认NO*/
@property (nonatomic, assign) BOOL isLandscape;
/**自動旋轉,默認YES*/
@property (nonatomic, assign) BOOL autoRotate;
/**全屏是否隐藏状态栏,默认YES*/
@property (nonatomic, assign) BOOL fullStatusBarHidden;
/** 静音(默认为NO)*/
Expand All @@ -38,6 +40,8 @@ typedef void(^BeyondBlock)();
@property (nonatomic, assign) VideoFillMode fillMode;
/**视频url*/
@property (nonatomic, strong) NSURL *url;
/**封面圖片*/
@property (nonatomic, strong) UIImageView *coverImageView;
/**进度条背景颜色*/
@property (nonatomic, strong) UIColor *progressBackgroundColor;
/**缓冲条缓冲进度颜色*/
Expand Down
55 changes: 36 additions & 19 deletions CLPlayer/CLPlayerView.m
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ - (CLPlayerMaskView *) maskView{
selector:@selector(disappear)
userInfo:nil
repeats:NO];
//封面圖片
_coverImageView = _maskView.coverImageView;
}
return _maskView;
}
Expand Down Expand Up @@ -145,6 +147,10 @@ -(void)setStrokeColor:(UIColor *)strokeColor{
-(void)setIsLandscape:(BOOL)isLandscape{
_isLandscape = isLandscape;
}
#pragma mark - 是否自動旋轉
-(void)setAutoRotate:(BOOL)autoRotate{
_autoRotate = autoRotate;
}
#pragma mark - 全屏状态栏是否隐藏
-(void)setFullStatusBarHidden:(BOOL)fullStatusBarHidden{
_fullStatusBarHidden = fullStatusBarHidden;
Expand Down Expand Up @@ -265,6 +271,7 @@ - (instancetype)initWithFrame:(CGRect)frame{
_mute = NO;
//查询控制器是否支持全屏
_isLandscape = NO;
_autoRotate = YES;
_isPlay = NO;
_statusBarHiddenState = self.statusBar.isHidden;
_toolBarDisappearTime = 10;
Expand Down Expand Up @@ -395,6 +402,14 @@ - (void)timeStack{
NSInteger durMin = (NSInteger)_playerItem.duration.value / _playerItem.duration.timescale / 60;//总分钟
NSInteger durSec = (NSInteger)_playerItem.duration.value / _playerItem.duration.timescale % 60;//总秒
self.maskView.totalTimeLabel.text = [NSString stringWithFormat:@"%02ld:%02ld", (long)durMin, (long)durSec];
AVURLAsset *urlAsset = (AVURLAsset *)_playerItem.asset;
NSArray *audioExt = @[@"mp3", @"wav", @"m4a", @"wma"];
if (urlAsset != nil && [audioExt containsObject:[urlAsset.URL.pathExtension lowercaseString]] ) {
self.maskView.coverImageView.hidden = false;
} else {
self.maskView.coverImageView.hidden = true;
}

}
}
#pragma mark - 播放暂停按钮方法
Expand Down Expand Up @@ -556,29 +571,31 @@ - (void)destroyTimer{
}
#pragma mark - 屏幕旋转通知
- (void)orientChange:(NSNotification *)notification{
UIDeviceOrientation orientation = [UIDevice currentDevice].orientation;
if (orientation == UIDeviceOrientationLandscapeLeft){
if (_isFullScreen == NO){
if (_isLandscape) {
//播放器所在控制器页面支持旋转情况下,和正常情况是相反的
[self fullScreenWithDirection:UIInterfaceOrientationLandscapeRight];
}else{
[self fullScreenWithDirection:UIInterfaceOrientationLandscapeLeft];
if (_autoRotate) {
UIDeviceOrientation orientation = [UIDevice currentDevice].orientation;
if (orientation == UIDeviceOrientationLandscapeLeft){
if (_isFullScreen == NO){
if (_isLandscape) {
//播放器所在控制器页面支持旋转情况下,和正常情况是相反的
[self fullScreenWithDirection:UIInterfaceOrientationLandscapeRight];
}else{
[self fullScreenWithDirection:UIInterfaceOrientationLandscapeLeft];
}
}
}
}
else if (orientation == UIDeviceOrientationLandscapeRight){
if (_isFullScreen == NO){
if (_isLandscape) {
[self fullScreenWithDirection:UIInterfaceOrientationLandscapeLeft];
}else{
[self fullScreenWithDirection:UIInterfaceOrientationLandscapeRight];
else if (orientation == UIDeviceOrientationLandscapeRight){
if (_isFullScreen == NO){
if (_isLandscape) {
[self fullScreenWithDirection:UIInterfaceOrientationLandscapeLeft];
}else{
[self fullScreenWithDirection:UIInterfaceOrientationLandscapeRight];
}
}
}
}
else if (orientation == UIDeviceOrientationPortrait){
if (_isFullScreen == YES){
[self originalscreen];
else if (orientation == UIDeviceOrientationPortrait){
if (_isFullScreen == YES){
[self originalscreen];
}
}
}
}
Expand Down
10 changes: 9 additions & 1 deletion CLPlayer/CLSlider.m
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ -(instancetype)initWithFrame:(CGRect)frame{
return self;
}
- (void)setup {
UIImage *thumbImage = [self getPictureWithName:@"CLRound"];
UIImage *thumbImage = [self imageWithImage:[self getPictureWithName:@"CLRound"] scaledToSize:CGSizeMake(25, 25)];
[self setThumbImage:thumbImage forState:UIControlStateHighlighted];
[self setThumbImage:thumbImage forState:UIControlStateNormal];
}
Expand Down Expand Up @@ -88,5 +88,13 @@ - (UIImage *)getPictureWithName:(NSString *)name{
return [UIImage imageWithContentsOfFile:path];
}

- (UIImage *)imageWithImage:(UIImage *)image scaledToSize:(CGSize)newSize {
UIGraphicsBeginImageContextWithOptions(newSize, NO, 0.0);
[image drawInRect:CGRectMake(0, 0, newSize.width, newSize.height)];
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return newImage;
}


@end
Binary file modified CLPlayer/Resource/CLPlayer.bundle/CLRound.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
@property (nonatomic, assign) BOOL repeatPlay;
/**是否支持横屏,默认NO*/
@property (nonatomic, assign) BOOL isLandscape;
/**自動旋轉,默認YES*/
@property (nonatomic, assign) BOOL autoRotate;
/**全屏是否隐藏状态栏,默认YES*/
@property (nonatomic, assign) BOOL fullStatusBarHidden;
/** 静音(默认为NO)*/
Expand All @@ -20,6 +22,8 @@
@property (nonatomic, assign) VideoFillMode fillMode;
/**视频url*/
@property (nonatomic, strong) NSURL *url;
/**封面圖片*/
@property (nonatomic, strong) UIImageView *coverImageView;
/**进度条背景颜色*/
@property (nonatomic, strong) UIColor *progressBackgroundColor;
/**缓冲条缓冲进度颜色*/
Expand Down