[IOS]对视频、音频播放器添加缓冲进度条
2015-06-30 17:10
465 查看
[IOS]对视频、音频播放器添加缓冲进度条
Demo地址:http://download.csdn.net/detail/u012881779/8854967
思路说起来很简单:
先拖一个Progress View控件,设置它的Progress Tint和Track Tint;
再拖一个Horizontal Slider覆盖在ProgressView上面,设置它的Min Track Tint 同时设置Max Track Tint为Clear Color(为了透过控件看见背后progressView的背景);
最后分别设置一下各进度的值就OK了。
Min Track Tint(播放进度)、Progress Tint(缓冲进度)、Track Tint(进度条背景)。
示意图:
Demo地址:http://download.csdn.net/detail/u012881779/8854967
思路说起来很简单:
先拖一个Progress View控件,设置它的Progress Tint和Track Tint;
再拖一个Horizontal Slider覆盖在ProgressView上面,设置它的Min Track Tint 同时设置Max Track Tint为Clear Color(为了透过控件看见背后progressView的背景);
最后分别设置一下各进度的值就OK了。
Min Track Tint(播放进度)、Progress Tint(缓冲进度)、Track Tint(进度条背景)。
@interface AVVideoViewController: UIViewController @property (weak, nonatomic) IBOutlet UISlider *mScrubber; //播放进度 @property (weak, nonatomic) IBOutlet UIProgressView *cacheProgressV;//缓冲进度 @end @implementation AVVideoViewController - (void)syncScrubber { /*播放进度*/ CMTime playerDuration = [self playerItemDuration]; if (CMTIME_IS_INVALID(playerDuration)) { mScrubber.minimumValue = 0.0; [self showStarLabletimeToEndLableTime:0.0 end:0.0]; return; } double duration = CMTimeGetSeconds(playerDuration); if (isfinite(duration)) { float minValue = [self.mScrubber minimumValue]; float maxValue = [self.mScrubber maximumValue]; double time = CMTimeGetSeconds([self.mPlayer currentTime]); [self showStarLabletimeToEndLableTime:time end:duration]; [self.mScrubber setValue:(maxValue - minValue) * time / duration + minValue]; } /*缓冲进度*/ NSTimeInterval timeInterval = [self availableDuration]; NSLog(@"Time I nterval:%f",timeInterval); CMTime duration11 = self.mPlayerItem.duration; CGFloat totalDuration = CMTimeGetSeconds(duration11); [_cacheProgressV setProgress:timeInterval / totalDuration animated:YES]; } // 计算缓冲进度 - (NSTimeInterval)availableDuration { NSArray *loadedTimeRanges = [[self.mPlayer currentItem] loadedTimeRanges]; CMTimeRange timeRange = [loadedTimeRanges.firstObject CMTimeRangeValue];// 获取缓冲区域 float startSeconds = CMTimeGetSeconds(timeRange.start); float durationSeconds = CMTimeGetSeconds(timeRange.duration); NSTimeInterval result = startSeconds + durationSeconds;// 计算缓冲总进度 return result; } @end
示意图:
相关文章推荐
- ios绘图
- [iOS]获取设备具体型号信息
- ios获取当前语言
- ios输入框被键盘挡住的解决办法
- iOS CoreImage图片处理动态渲染(滤镜)
- ios8 自动安装不好用的问题
- iOS6中的Auto Layout:通过代码添加约束
- iOS and OS X Network Programming Cookbook |Retrieving network address information
- iOS开发拓展篇-XMPP简单介绍
- iOS开发拓展篇—应用之间的跳转和数据传递
- iOS开发拓展篇—xib中关于拖拽手势的潜在错误
- iOS开发拓展篇—音频处理(音乐播放器6)
- iOS开发拓展篇—音频处理(音乐播放器5)
- iOS开发拓展篇—音频处理(音乐播放器4)
- iOS开发拓展篇—音频处理(音乐播放器3)
- iOS开发拓展篇—音频处理(音乐播放器2)
- iOS开发拓展篇—音频处理(音乐播放器1)
- iOS开发拓展篇—CoreLocation地理编码
- iOS开发拓展篇—CoreLocation定位服务
- 仿制新浪微博iOS客户端之四-未登录页面处理