iOS————使用NSdate获取播放时间
2014-06-16 13:43
519 查看
通过
- (id)addPeriodicTimeObserverForInterval:(CMTime)interval queue:(dispatch_queue_t)queue
usingBlock:(void (^)(CMTime time))block;
这个函数来控制获取时间的刷新率
例如:
[_LGCustomMoviePlayerController.player
addPeriodicTimeObserverForInterval:CMTimeMake(1,
1) queue:NULL
usingBlock:^(CMTime time){
//获取当前时间
CMTime currentTime =
_LGCustomMoviePlayerController.player.currentItem.currentTime;
//转成秒数
double currentPlayTime = currentTime.value/currentTime.timescale;
//进度条的value
_movieProgressSlider.value = currentPlayTime/totalMovieDuration;
//把时间转化成 NSDate 格式
NSDate *d = [NSDate
dateWithTimeIntervalSince1970:currentPlayTime];
// d 的打印形式为:1970——1——1 xx:xx:xx 我们需要的是 xx:xx:xx,然后进行显示
NSString *currentTimeStr = [NSString
stringWithFormat:@"%@",d];
NSRange range;
range.location =
11;
range.length =
8;
NSString *showtime = [currentTimeStr
substringWithRange:range];
self.currentTimeLabel.text = showtime;
}];
其中CMTimeMake(1,1)表示的是:刷新一次/秒,即检测的频率;也相当于说视频显示的时间是以秒为单位进行递进的。
- (id)addPeriodicTimeObserverForInterval:(CMTime)interval queue:(dispatch_queue_t)queue
usingBlock:(void (^)(CMTime time))block;
这个函数来控制获取时间的刷新率
例如:
[_LGCustomMoviePlayerController.player
addPeriodicTimeObserverForInterval:CMTimeMake(1,
1) queue:NULL
usingBlock:^(CMTime time){
//获取当前时间
CMTime currentTime =
_LGCustomMoviePlayerController.player.currentItem.currentTime;
//转成秒数
double currentPlayTime = currentTime.value/currentTime.timescale;
//进度条的value
_movieProgressSlider.value = currentPlayTime/totalMovieDuration;
//把时间转化成 NSDate 格式
NSDate *d = [NSDate
dateWithTimeIntervalSince1970:currentPlayTime];
// d 的打印形式为:1970——1——1 xx:xx:xx 我们需要的是 xx:xx:xx,然后进行显示
NSString *currentTimeStr = [NSString
stringWithFormat:@"%@",d];
NSRange range;
range.location =
11;
range.length =
8;
NSString *showtime = [currentTimeStr
substringWithRange:range];
self.currentTimeLabel.text = showtime;
}];
其中CMTimeMake(1,1)表示的是:刷新一次/秒,即检测的频率;也相当于说视频显示的时间是以秒为单位进行递进的。
相关文章推荐
- iOS开发中获取上月的起止时间(NSCalendar、NSDateComponents和NSDate的使用)
- iOS NSDate的基本使用,获取时间戳
- iOS-获取视频长度和当前播放时间
- iOS获取当前时间 NSDate(NSCalendar)获取当前时间
- 使用getid3插件获取文件播放时间
- iOS积累--字符串转化为NSDate, 获取当前时区的系统时间
- IOS MPMoviePlayerViewController 获取当前音频文件播放时间点
- iOS-获取视频长度和当前播放时间
- php使用FFmpeg接口获取视频的播放时长、码率、缩略图以及创建时间
- NSDate相关处理,获取当前时间戳,获取本地时间,获取星期 iOS新手笔记
- 18-OC中NSDate的使用(转换时间,计算时间差,获取时间的每一部分)
- IOS NSDate获取的时间比系统时间长1年
- ios正在使用NSDateComponents、NSDate、NSCalendar它的结论是在当前时间是在一段时间在一天。
- iOS NSDateFormatter 和 NSDate简单使用 时间戳的转换
- NSDate 使用 ios时间的秒数
- ios 获取时间--NSCalendar NSDateComponents NSDate
- iOS 开发获取当前时间 NSDate
- iOS开发-NSDate获取当前时区时间
- iOS开发学习专题-基础知识(五) NSDate时间 NSUserDefaults本地存储 NSNotification系统通知的详细使用方式
- iOS NSDate等时间类的使用