diff --git a/CLPlayer/CLPlayerMaskView.h b/CLPlayer/CLPlayerMaskView.h index b5a8121..c87e042 100755 --- a/CLPlayer/CLPlayerMaskView.h +++ b/CLPlayer/CLPlayerMaskView.h @@ -49,6 +49,8 @@ @property (nonatomic,strong) CLSlider *slider; /**加载失败按钮*/ @property (nonatomic,strong) UIButton *failButton; +/**封面圖片*/ +@property (nonatomic,strong) UIImageView *coverImageView; /**代理人*/ @property (nonatomic,weak) id delegate; /**进度条背景颜色*/ diff --git a/CLPlayer/CLPlayerMaskView.m b/CLPlayer/CLPlayerMaskView.m index 4b37335..84d13a4 100755 --- a/CLPlayer/CLPlayerMaskView.m +++ b/CLPlayer/CLPlayerMaskView.m @@ -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]; @@ -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); @@ -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{ diff --git a/CLPlayer/CLPlayerView.h b/CLPlayer/CLPlayerView.h index df508d0..4b4429f 100755 --- a/CLPlayer/CLPlayerView.h +++ b/CLPlayer/CLPlayerView.h @@ -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)*/ @@ -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; /**缓冲条缓冲进度颜色*/ diff --git a/CLPlayer/CLPlayerView.m b/CLPlayer/CLPlayerView.m index 0d28866..aa2ab6f 100755 --- a/CLPlayer/CLPlayerView.m +++ b/CLPlayer/CLPlayerView.m @@ -94,6 +94,8 @@ - (CLPlayerMaskView *) maskView{ selector:@selector(disappear) userInfo:nil repeats:NO]; + //封面圖片 + _coverImageView = _maskView.coverImageView; } return _maskView; } @@ -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; @@ -265,6 +271,7 @@ - (instancetype)initWithFrame:(CGRect)frame{ _mute = NO; //查询控制器是否支持全屏 _isLandscape = NO; + _autoRotate = YES; _isPlay = NO; _statusBarHiddenState = self.statusBar.isHidden; _toolBarDisappearTime = 10; @@ -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 - 播放暂停按钮方法 @@ -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]; + } } } } diff --git a/CLPlayer/CLSlider.m b/CLPlayer/CLSlider.m index 95ed3de..52ecee4 100755 --- a/CLPlayer/CLSlider.m +++ b/CLPlayer/CLSlider.m @@ -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]; } @@ -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 diff --git a/CLPlayer/Resource/CLPlayer.bundle/CLRound.png b/CLPlayer/Resource/CLPlayer.bundle/CLRound.png index e617f3d..b7c7a26 100755 Binary files a/CLPlayer/Resource/CLPlayer.bundle/CLRound.png and b/CLPlayer/Resource/CLPlayer.bundle/CLRound.png differ diff --git a/README.md b/README.md index 3e8dc3f..baaf5d9 100755 --- a/README.md +++ b/README.md @@ -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)*/ @@ -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; /**缓冲条缓冲进度颜色*/