├── CCVideoPlayer.bundle ├── fast_back.png ├── fast_forward.png ├── thumbImage@2x.png ├── full_pause_btn@2x.png ├── full_pause_btn@3x.png ├── full_play_btn@2x.png ├── full_play_btn@3x.png ├── MaximumTrackImage@2x.png ├── MinimumTrackImage@2x.png ├── bg_media_default@2x.jpg ├── full_minimize_btn@2x.png ├── full_minimize_btn@3x.png ├── full_pause_btn_hl@2x.png ├── full_pause_btn_hl@3x.png ├── full_play_btn_hl@2x.png ├── full_play_btn_hl@3x.png ├── full_minimize_btn_hl@2x.png ├── full_minimize_btn_hl@3x.png ├── mini_launchFullScreen_btn@2x.png ├── mini_launchFullScreen_btn@3x.png ├── mini_launchFullScreen_btn_hl@2x.png └── mini_launchFullScreen_btn_hl@3x.png ├── CCFullViewController.h ├── .gitignore ├── README.md ├── CCFullViewController.m ├── CCVideoPlayView.h ├── CCVideoPlayView.xib └── CCVideoPlayView.m /CCVideoPlayer.bundle/fast_back.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cocos543/CCVideoPlayer/HEAD/CCVideoPlayer.bundle/fast_back.png -------------------------------------------------------------------------------- /CCVideoPlayer.bundle/fast_forward.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cocos543/CCVideoPlayer/HEAD/CCVideoPlayer.bundle/fast_forward.png -------------------------------------------------------------------------------- /CCVideoPlayer.bundle/thumbImage@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cocos543/CCVideoPlayer/HEAD/CCVideoPlayer.bundle/thumbImage@2x.png -------------------------------------------------------------------------------- /CCVideoPlayer.bundle/full_pause_btn@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cocos543/CCVideoPlayer/HEAD/CCVideoPlayer.bundle/full_pause_btn@2x.png -------------------------------------------------------------------------------- /CCVideoPlayer.bundle/full_pause_btn@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cocos543/CCVideoPlayer/HEAD/CCVideoPlayer.bundle/full_pause_btn@3x.png -------------------------------------------------------------------------------- /CCVideoPlayer.bundle/full_play_btn@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cocos543/CCVideoPlayer/HEAD/CCVideoPlayer.bundle/full_play_btn@2x.png -------------------------------------------------------------------------------- /CCVideoPlayer.bundle/full_play_btn@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cocos543/CCVideoPlayer/HEAD/CCVideoPlayer.bundle/full_play_btn@3x.png -------------------------------------------------------------------------------- /CCVideoPlayer.bundle/MaximumTrackImage@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cocos543/CCVideoPlayer/HEAD/CCVideoPlayer.bundle/MaximumTrackImage@2x.png -------------------------------------------------------------------------------- /CCVideoPlayer.bundle/MinimumTrackImage@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cocos543/CCVideoPlayer/HEAD/CCVideoPlayer.bundle/MinimumTrackImage@2x.png -------------------------------------------------------------------------------- /CCVideoPlayer.bundle/bg_media_default@2x.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cocos543/CCVideoPlayer/HEAD/CCVideoPlayer.bundle/bg_media_default@2x.jpg -------------------------------------------------------------------------------- /CCVideoPlayer.bundle/full_minimize_btn@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cocos543/CCVideoPlayer/HEAD/CCVideoPlayer.bundle/full_minimize_btn@2x.png -------------------------------------------------------------------------------- /CCVideoPlayer.bundle/full_minimize_btn@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cocos543/CCVideoPlayer/HEAD/CCVideoPlayer.bundle/full_minimize_btn@3x.png -------------------------------------------------------------------------------- /CCVideoPlayer.bundle/full_pause_btn_hl@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cocos543/CCVideoPlayer/HEAD/CCVideoPlayer.bundle/full_pause_btn_hl@2x.png -------------------------------------------------------------------------------- /CCVideoPlayer.bundle/full_pause_btn_hl@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cocos543/CCVideoPlayer/HEAD/CCVideoPlayer.bundle/full_pause_btn_hl@3x.png -------------------------------------------------------------------------------- /CCVideoPlayer.bundle/full_play_btn_hl@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cocos543/CCVideoPlayer/HEAD/CCVideoPlayer.bundle/full_play_btn_hl@2x.png -------------------------------------------------------------------------------- /CCVideoPlayer.bundle/full_play_btn_hl@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cocos543/CCVideoPlayer/HEAD/CCVideoPlayer.bundle/full_play_btn_hl@3x.png -------------------------------------------------------------------------------- /CCVideoPlayer.bundle/full_minimize_btn_hl@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cocos543/CCVideoPlayer/HEAD/CCVideoPlayer.bundle/full_minimize_btn_hl@2x.png -------------------------------------------------------------------------------- /CCVideoPlayer.bundle/full_minimize_btn_hl@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cocos543/CCVideoPlayer/HEAD/CCVideoPlayer.bundle/full_minimize_btn_hl@3x.png -------------------------------------------------------------------------------- /CCVideoPlayer.bundle/mini_launchFullScreen_btn@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cocos543/CCVideoPlayer/HEAD/CCVideoPlayer.bundle/mini_launchFullScreen_btn@2x.png -------------------------------------------------------------------------------- /CCVideoPlayer.bundle/mini_launchFullScreen_btn@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cocos543/CCVideoPlayer/HEAD/CCVideoPlayer.bundle/mini_launchFullScreen_btn@3x.png -------------------------------------------------------------------------------- /CCVideoPlayer.bundle/mini_launchFullScreen_btn_hl@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cocos543/CCVideoPlayer/HEAD/CCVideoPlayer.bundle/mini_launchFullScreen_btn_hl@2x.png -------------------------------------------------------------------------------- /CCVideoPlayer.bundle/mini_launchFullScreen_btn_hl@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cocos543/CCVideoPlayer/HEAD/CCVideoPlayer.bundle/mini_launchFullScreen_btn_hl@3x.png -------------------------------------------------------------------------------- /CCFullViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // CCFullViewController.h 3 | // 4 | // 5 | // Created by Cocos on 16/3/2. 6 | // Copyright © 2016年 Cocos. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface CCFullViewController : UIViewController 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Xcode 2 | .DS_Store 3 | Build 4 | */build/* 5 | *.pbxuser 6 | !default.pbxuser 7 | *.mode1v3 8 | !default.mode1v3 9 | *.mode2v3 10 | !default.mode2v3 11 | *.perspectivev3 12 | !default.perspectivev3 13 | xcuserdata 14 | profile 15 | *.moved-aside 16 | DerivedData 17 | .idea/ 18 | *.hmap 19 | *.xccheckout 20 | *.xcworkspace 21 | !default.xcworkspace 22 | include/ 23 | lib/ 24 | Excalibur/scripts/ 25 | UmengAnalytics/ 26 | UMengFeedback/ 27 | 28 | #CocoaPods 29 | Pods 30 | *.lock 31 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # CC視頻播放器 2 | 3 | ## 更新日記 4 | 最後更新 2016年3月 5 | 6 | ## 前言 7 |   壹個iOS上使用的RTMP視頻組件,基於VLCKit開發,用於播放RTMP流,另外幾乎支持所有視頻格式.適合做iOS端直播開發,或者本地視頻播放器使用.基於老牌開源播放器VLC核心組件開發,高效可靠. 8 | 9 | ## 主要功能 10 | 1. 播放器的基本功能. 11 | 2. 支持RTMP協議視頻流. 12 | 3. 支持全屏播放. 13 | 14 | ## 使用方法 15 | 1.先使用Pod導入核心庫 16 | Pod: 17 | 18 | pod 'MobileVLCKit-prod', '2.7.2' 19 | 20 | 2.在需要加載播放器的地方引入#import "CCVideoPlayView.h" 21 | 3.加載播放器 22 | ``` objectivec 23 | // UIViewController.m 24 | // 初始化 25 | CCVideoPlayView *playView = [CCVideoPlayView videoPlayViewWithFrame:frame URL:playerURL delegate:self]; 26 | 27 | //設置指示器顏色 28 | playView.indicatorColor 29 | 30 | //設置用於載入播放器的容器 31 | playView.containerViewController = self; 32 | 33 | //顯示播放器 34 | [self.view addSubview:self.ccPlayView]; 35 | ``` 36 | 37 | 4.其他用法參考頭文件CCVideoPlayView.h 38 | -------------------------------------------------------------------------------- /CCFullViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // CCFullViewController.m 3 | // 4 | // 5 | // Created by Cocos on 16/3/2. 6 | // Copyright © 2016年 Cocos. All rights reserved. 7 | // 8 | 9 | #import "CCFullViewController.h" 10 | 11 | @interface CCFullViewController () 12 | 13 | @end 14 | 15 | @implementation CCFullViewController 16 | 17 | -(void)loadView{ 18 | [super loadView]; 19 | self.view = [[UIView alloc] init]; 20 | // self.view.alpha = 0; 21 | } 22 | 23 | - (void)viewDidLoad { 24 | [super viewDidLoad]; 25 | // Do any additional setup after loading the view. 26 | } 27 | 28 | - (void)didReceiveMemoryWarning { 29 | [super didReceiveMemoryWarning]; 30 | // Dispose of any resources that can be recreated. 31 | } 32 | 33 | 34 | - (UIInterfaceOrientationMask)supportedInterfaceOrientations{ 35 | return UIInterfaceOrientationMaskLandscapeRight; 36 | } 37 | 38 | @end 39 | -------------------------------------------------------------------------------- /CCVideoPlayView.h: -------------------------------------------------------------------------------- 1 | // 2 | // CCVideoPlayView.h 3 | // 4 | // 5 | // Created by 郑克明 on 16/3/1. 6 | // Copyright © 2016年 Cocos. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @protocol CCVideoPlayViewDelegate 12 | @optional 13 | /** 14 | * 触摸播放器 15 | * 16 | * @param sender 触发的手势对象 17 | */ 18 | -(void)CCPlayerOnTapPlayView:(_Nullable id)sender; 19 | /** 20 | * 开始播放 21 | */ 22 | -(void)CCPlayerOnPlay; 23 | /** 24 | * 播放暂停 25 | */ 26 | -(void)CCPlayerOnPause; 27 | /** 28 | * 播放停止 29 | */ 30 | -(void)CCPlayerOnStop; 31 | /** 32 | * 切换成横屏模式 33 | */ 34 | -(void)CCPlayerOnSwitchFullModel; 35 | /** 36 | * 切换成竖屏模式 37 | */ 38 | -(void)CCPlayerOnSwitchPortraitModel; 39 | /** 40 | * 工具栏显示 41 | */ 42 | -(void)CCPlayerOnToolViewShow; 43 | /** 44 | * 工具栏隐藏 45 | */ 46 | -(void)CCPlayerOnToolViewHide; 47 | 48 | 49 | /// status 变更回调 50 | - (void)mediaPlayerStateChanged:(nonnull NSNotification *)aNotification; 51 | - (void)mediaPlayerTimeChanged:(nonnull NSNotification *)aNotification; 52 | @end 53 | 54 | 55 | //工具栏显示时长(超时后自动隐藏) 56 | extern NSInteger const CCPlayerShowToolTimeInterval; 57 | 58 | @interface CCVideoPlayView : UIView 59 | 60 | @property (nonatomic,strong,nonnull) NSURL *url; 61 | 62 | @property (nonatomic,readonly) BOOL isPlaying; 63 | 64 | @property (nonatomic,readonly) BOOL willlaying; 65 | 66 | @property (nonatomic,strong, nullable) UIColor *indicatorColor; 67 | //用于显示全屏的控制器 68 | @property (nonatomic,weak,nullable) UIViewController *containerViewController; 69 | //代理 70 | @property (nonatomic,weak,nullable) id delegate; 71 | /** 72 | * 从xib文件中创建视图 73 | * 74 | * @return CCVideoPlayView 75 | */ 76 | + (instancetype _Nonnull)videoPlayViewWithFrame:(CGRect)frame URL:(nonnull NSURL *)url delegate:(_Nullable id )delegate; 77 | 78 | /** 79 | * 停止播放 80 | */ 81 | - (void)stopPlay; 82 | /** 83 | * 开始播放 84 | */ 85 | - (void)startPlay; 86 | @end 87 | -------------------------------------------------------------------------------- /CCVideoPlayView.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 32 | 33 | 34 | 35 | 36 | 37 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | -------------------------------------------------------------------------------- /CCVideoPlayView.m: -------------------------------------------------------------------------------- 1 | // 2 | // CCVideoPlayView.m 3 | // 4 | // 5 | // Created by Cocos on 16/3/1. 6 | // Copyright © 2016年 Cocos. All rights reserved. 7 | // 8 | #import 9 | #import "CCVideoPlayView.h" 10 | #import "CCFullViewController.h" 11 | 12 | #define kVLCSettingNetworkCaching @"network-caching" 13 | #define kVLCSettingNetworkCachingDefaultValue @(999) 14 | NSInteger const CCPlayerShowToolTimeInterval = 3; 15 | static NSString *status[] = { 16 | @"VLCMediaPlayerStateStopped", //< Player has stopped 17 | @"VLCMediaPlayerStateOpening", //< Stream is opening 18 | @"VLCMediaPlayerStateBuffering", //< Stream is buffering 19 | @"VLCMediaPlayerStateEnded", //< Stream has ended 20 | @"VLCMediaPlayerStateError", //< Player has generated an error 21 | @"VLCMediaPlayerStatePlaying", //< Stream is playing 22 | @"VLCMediaPlayerStatePaused" 23 | }; 24 | @interface CCVideoPlayView() 25 | //用户展示视频,默认展示播放器背景图 26 | @property (weak, nonatomic) IBOutlet UIImageView *imageView; 27 | @property (weak, nonatomic) IBOutlet UIView *toolView; 28 | /** 29 | * playOrPauseBtn 被选中,表示播放状态,未选中,表示暂停状态 30 | */ 31 | @property (weak, nonatomic) IBOutlet UIButton *playOrPauseBtn; 32 | @property (weak, nonatomic) IBOutlet UIButton *switchOrientation; 33 | @property (weak, nonatomic) IBOutlet UISlider *volumeSlider; 34 | 35 | //播放器驱动 36 | @property (nonatomic,strong) VLCMediaPlayer *player; 37 | //播放器绘制层 38 | @property (nonatomic,strong) UIView *playerView; 39 | //工具栏定时器 40 | @property (nonatomic,strong) NSTimer *toolViewTimer; 41 | //工具栏动画是否正在执行 42 | @property (nonatomic) BOOL isToolViewShowAnimating; 43 | @property (nonatomic) BOOL isToolViewHideAnimating; 44 | 45 | //全屏控制器(暂无) 46 | @property (nonatomic,weak) CCFullViewController *fullVC; 47 | //CCVideoPlayView最初被指定的原始位置 48 | @property (nonatomic) CGRect originalViewFrame; 49 | @property (nonatomic) BOOL isFullModel; 50 | @end 51 | 52 | @implementation CCVideoPlayView 53 | 54 | + (instancetype)videoPlayViewWithFrame:(CGRect)frame URL:(NSURL *)url delegate:(id)delegate{ 55 | CCVideoPlayView *view = (CCVideoPlayView *)[[[NSBundle mainBundle] loadNibNamed:@"CCVideoPlayView" owner:nil options:nil] firstObject]; 56 | if (view) { 57 | view.imageView.translatesAutoresizingMaskIntoConstraints = NO; 58 | view.playerView = [[UIView alloc] initWithFrame:CGRectZero]; 59 | view.url = url; 60 | 61 | //播放器驱动设置 62 | view.player = [[VLCMediaPlayer alloc] initWithOptions:@[[NSString stringWithFormat:@"--extraintf"], [NSString stringWithFormat:@"--%@=%@", kVLCSettingNetworkCaching,@(1000)]]]; 63 | 64 | view.player.media = [VLCMedia mediaWithURL:url]; 65 | view.player.drawable = view.playerView; 66 | view.player.delegate = view; 67 | view.delegate = delegate; 68 | view.originalViewFrame = frame; 69 | view.frame = frame; 70 | [view playOrPause:nil]; 71 | [view addObservers]; 72 | } 73 | return view; 74 | } 75 | 76 | -(instancetype)init{ 77 | @throw [NSException exceptionWithName:@"Not supported init" reason:@"Use +[CCVideoPlayView videoPlayView]" userInfo:nil]; 78 | } 79 | 80 | -(void)awakeFromNib{ 81 | [super awakeFromNib]; 82 | // [self.volumeSlider setMinimumTrackImage:[UIImage imageNamed:@"MinimumTrackImage"] forState:UIControlStateNormal]; 83 | // [self.volumeSlider setMaximumTrackImage:[UIImage imageNamed:@"MaximumTrackImage"] forState:UIControlStateNormal]; 84 | [self.volumeSlider setThumbImage:[UIImage imageNamed:@"thumbImage"] forState:UIControlStateNormal]; 85 | 86 | //添加所有手势操作 87 | UITapGestureRecognizer *tapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(singleTap:)]; 88 | tapRecognizer.numberOfTapsRequired = 1; 89 | [self addGestureRecognizer:tapRecognizer]; 90 | } 91 | 92 | -(void)willMoveToSuperview:(UIView *)newSuperview{ 93 | [super willMoveToSuperview:newSuperview]; 94 | 95 | if (!newSuperview) { 96 | [self removeObservers]; 97 | if (self.player.isPlaying) { 98 | [self.player stop]; 99 | } 100 | self.player.drawable = nil; 101 | self.player = nil; 102 | [self removeToolViewTimer]; 103 | } 104 | } 105 | 106 | -(void)dealloc{ 107 | NSLog(@"ccview dealloc~"); 108 | } 109 | 110 | #pragma mark - 布局调试 111 | - (void)layoutSubviews 112 | { 113 | [super layoutSubviews]; 114 | for (UIView *subView in self.subviews) { 115 | if ([subView hasAmbiguousLayout]) { 116 | NSLog(@"AMBIGUOUS: %@", subView); 117 | } 118 | } 119 | 120 | //防止有时候旋转屏幕时出现偏差 121 | if (!self.isFullModel) { 122 | self.frame = self.originalViewFrame; 123 | self.playerView.frame = self.imageView.frame; 124 | } 125 | } 126 | 127 | #pragma mark - 界面调整 128 | 129 | -(void)imageViewFrameDidChange:(NSDictionary *)change{ 130 | NSLog(@"imageView frame did change %@",NSStringFromCGRect(self.imageView.frame)); 131 | // self.playerView.frame = self.imageView.frame; 132 | } 133 | 134 | #pragma mark - KVO监听 135 | - (void)addObservers 136 | { 137 | [self addObserver:self forKeyPath:@"frame" options:NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld context:nil]; 138 | } 139 | 140 | - (void)removeObservers 141 | { 142 | [self removeObserver:self forKeyPath:@"frame"]; 143 | } 144 | 145 | - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context 146 | { 147 | if ([keyPath isEqualToString:@"frame"]) { 148 | [self imageViewFrameDidChange:change]; 149 | } 150 | } 151 | 152 | #pragma mark - 播放器工具栏操作 153 | /** 154 | * 播放与暂停播放 155 | * 156 | * @param sender 播放(暂停)按钮 157 | */ 158 | - (IBAction)playOrPause:(UIButton *)sender { 159 | //按钮未选中:准备播放.如果是播放,则开启定时器,定时隐藏工具栏,更改按钮为暂停图标 160 | //按钮被选中:准备暂停.如果是暂停,则显示工具栏,移除定时器,更改按钮为播放图标 161 | if (!sender) { 162 | //首次播放,系统自动触发点击事件,sender为nil 163 | //这里没有设置palyerView的frame,需要在imageView自动根据约束更新frame时候调整palyerView的frame 164 | UIView *playerView = self.playerView; 165 | [self.imageView addSubview:playerView]; 166 | [self.player play]; 167 | self.playOrPauseBtn.selected = YES; 168 | }else if (sender.selected) { 169 | [self.player stop]; 170 | }else{ 171 | [self.player play]; 172 | } 173 | sender.selected = !sender.selected; 174 | } 175 | /** 176 | * 全屏切换 177 | * 由CCVideoPlayView父视图所在的控制器负责显示全屏 178 | * @param sender 全屏切换按钮 179 | */ 180 | - (IBAction)switchOrientation:(UIButton *)sender { 181 | if (sender.selected) { 182 | //切换正常 183 | [self.fullVC dismissViewControllerAnimated:NO completion:^{ 184 | [self.containerViewController.view addSubview:self]; 185 | //视频驱动层的大小和imageView一样大,而imageView自适应self.frame 186 | [UIView animateWithDuration:0.15 delay:0 options:UIViewAnimationOptionLayoutSubviews animations:^{ 187 | self.frame = self.originalViewFrame; 188 | self.playerView.frame = self.imageView.frame; 189 | } completion:^(BOOL finished){ 190 | if (finished) { 191 | //防止在动画执行的时候触发layoutSubviews方法中关于frame的代码 192 | self.isFullModel = NO; 193 | } 194 | }]; 195 | }]; 196 | sender.selected = NO; 197 | if ([self.delegate respondsToSelector:@selector(CCPlayerOnSwitchPortraitModel)]) { 198 | [self.delegate CCPlayerOnSwitchPortraitModel]; 199 | } 200 | }else{ 201 | //切换全屏 202 | self.isFullModel = YES; 203 | CCFullViewController *fullVC = [[CCFullViewController alloc] init]; 204 | [self.containerViewController presentViewController:fullVC animated:NO completion:^{ 205 | //注意此时高<宽,所以视频高等于屏幕高,视频宽为视频高的3/4 206 | [fullVC.view addSubview:self]; 207 | self.playerView.frame = CGRectMake(0, 0, fullVC.view.frame.size.height * 4 / 3, fullVC.view.frame.size.height); 208 | self.center = fullVC.view.center; 209 | self.playerView.center = self.center; 210 | [UIView animateWithDuration:0.15 delay:0 options:UIViewAnimationOptionLayoutSubviews animations:^{ 211 | self.frame = fullVC.view.bounds; 212 | } completion:nil]; 213 | }]; 214 | self.fullVC = fullVC; 215 | sender.selected = YES; 216 | if ([self.delegate respondsToSelector:@selector(CCPlayerOnSwitchFullModel)]) { 217 | [self.delegate CCPlayerOnSwitchFullModel]; 218 | } 219 | } 220 | 221 | [self removeToolViewTimer]; 222 | [self addToolViewTimer]; 223 | } 224 | 225 | /** 226 | * 切换工具视图显示或隐藏 227 | * 228 | * @param isShowView 显示或者隐藏视图 229 | */ 230 | - (void)setToolViewShowState:(BOOL)isShowView{ 231 | if (isShowView) { 232 | [self removeToolViewTimer]; 233 | [self showToolView]; 234 | //重新添加定时器 235 | [self addToolViewTimer]; 236 | }else{ 237 | [self removeToolViewTimer]; 238 | if (self.player.state != VLCMediaPlayerStateStopped) { 239 | [self hideToolView]; 240 | } 241 | } 242 | } 243 | 244 | /** 245 | * 隐藏工具栏 246 | */ 247 | - (void)hideToolView{ 248 | self.isToolViewHideAnimating = YES; 249 | [UIView animateWithDuration:1 animations:^{ 250 | self.toolView.alpha = 0; 251 | } completion:^(BOOL finished){ 252 | if (finished) { 253 | self.isToolViewHideAnimating = NO; 254 | } 255 | }]; 256 | if ([self.delegate respondsToSelector:@selector(CCPlayerOnToolViewHide)]) { 257 | [self.delegate CCPlayerOnToolViewHide]; 258 | } 259 | } 260 | 261 | /** 262 | * 显示工具栏 263 | */ 264 | - (void)showToolView{ 265 | self.isToolViewShowAnimating = YES; 266 | [UIView animateWithDuration:0.5 animations:^{ 267 | self.toolView.alpha = 1; 268 | } completion:^(BOOL finished){ 269 | if (finished) { 270 | self.isToolViewShowAnimating = NO; 271 | } 272 | }]; 273 | if ([self.delegate respondsToSelector:@selector(CCPlayerOnToolViewShow)]) { 274 | [self.delegate CCPlayerOnToolViewShow]; 275 | } 276 | } 277 | 278 | #pragma mark - 定时器操作 279 | /** 280 | * 定时隐藏工具栏 281 | */ 282 | - (void)addToolViewTimer{ 283 | self.toolViewTimer = [[NSTimer alloc] initWithFireDate: [NSDate dateWithTimeIntervalSinceNow:CCPlayerShowToolTimeInterval] interval:0 target:self selector:@selector(hideToolView) userInfo:nil repeats:NO]; 284 | NSRunLoop *runLoop = [NSRunLoop currentRunLoop]; 285 | [runLoop addTimer:self.toolViewTimer forMode:NSDefaultRunLoopMode]; 286 | NSLog(@"addToolViewTimer"); 287 | } 288 | 289 | /** 290 | * 移除工具栏隐藏定时器 291 | */ 292 | - (void)removeToolViewTimer{ 293 | //移除定时器 294 | if (self.toolViewTimer) { 295 | [self.toolViewTimer invalidate]; 296 | self.toolViewTimer = nil; 297 | } 298 | NSLog(@"removeToolViewTimer"); 299 | } 300 | 301 | 302 | /** 303 | * 某些操作需要定时器重新计时 304 | */ 305 | - (void)updateToolViewTimer{ 306 | 307 | } 308 | 309 | #pragma mark - 手势操作 310 | -(void)singleTap:(id)sender{ 311 | if (self.toolView.alpha > 0.001) { 312 | [self setToolViewShowState:NO]; 313 | }else{ 314 | [self setToolViewShowState:YES]; 315 | } 316 | if ([self.delegate respondsToSelector:@selector(CCPlayerOnTapPlayView:)]) { 317 | [self.delegate CCPlayerOnTapPlayView:sender]; 318 | } 319 | } 320 | 321 | #pragma mark - 实现VLCMediaPlayer部分协议 322 | 323 | /// status 变更回调 324 | - (void)mediaPlayerStateChanged:(NSNotification *)aNotification{ 325 | NSLog(@"State: %@", status[self.player.state]); 326 | //可能是VLC的bug,没有VLCMediaPlayerStatePlaying状态,只有buffing状态 327 | if (self.player.isPlaying) { 328 | [self addToolViewTimer]; 329 | [self stopLoadingIndicator]; 330 | }else if (VLCMediaPlayerStateStopped == self.player.state) { 331 | [self removeToolViewTimer]; 332 | [self showToolView]; 333 | [self stopLoadingIndicator]; 334 | [self stopPlay]; 335 | }else if (VLCMediaPlayerStateBuffering == self.player.state){ 336 | [self startLoadingIndicator]; 337 | } 338 | 339 | if ([self.delegate respondsToSelector:@selector(mediaPlayerStateChanged:)]) { 340 | [self.delegate mediaPlayerStateChanged:aNotification]; 341 | } 342 | } 343 | 344 | - (void)mediaPlayerTimeChanged:(NSNotification *)aNotification{ 345 | // NSLog(@"State: %@", aNotification); 346 | } 347 | 348 | #pragma mark - 其他相关操作 349 | 350 | - (void)stopPlay { 351 | if (self.playOrPauseBtn.selected == YES) { 352 | [self playOrPause:self.playOrPauseBtn]; 353 | } 354 | } 355 | 356 | - (void)startPlay { 357 | if (self.playOrPauseBtn.selected == NO) { 358 | [self playOrPause:self.playOrPauseBtn]; 359 | } 360 | } 361 | 362 | //添加加载指示器 363 | - (void)startLoadingIndicator{ 364 | 365 | if ([self.imageView viewWithTag:1008]) { 366 | return; 367 | } 368 | UIColor *color = self.indicatorColor == nil ? [UIColor redColor] : self.indicatorColor; 369 | UIActivityIndicatorView *activityIndicator= [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge]; 370 | activityIndicator.center = self.imageView.center; 371 | [activityIndicator setColor:color]; 372 | activityIndicator.tag=1008; 373 | [self.imageView addSubview:activityIndicator]; 374 | [activityIndicator startAnimating]; 375 | } 376 | 377 | //移除加载指示器 378 | - (void)stopLoadingIndicator{ 379 | UIActivityIndicatorView *activityIndicator=[self.imageView viewWithTag:1008]; 380 | [activityIndicator stopAnimating]; 381 | [activityIndicator removeFromSuperview]; 382 | } 383 | 384 | @end 385 | 386 | --------------------------------------------------------------------------------