一. //传入 秒 得到 xx分钟xx秒 格式 00:56
//传入 秒 得到 xx分钟xx秒
-(NSString *)getMMSSFromSS:(NSString *)totalTime{
NSInteger seconds = [totalTime integerValue];
//format of minute
NSString *str_minute;
if (seconds/60<10) {
str_minute= [NSString stringWithFormat:@"0%ld",seconds/60];
}else{
str_minute= [NSString stringWithFormat:@"%ld",seconds/60];
}
//format of second
NSString *str_second;
if (seconds%60<10) {
str_second= [NSString stringWithFormat:@"0%ld",seconds%60];
}else{
str_second= [NSString stringWithFormat:@"%ld",seconds%60];
}
//format of time
NSString *format_time = [NSString stringWithFormat:@"%@:%@",str_minute,str_second];
NSLog(@"format_time : %@",format_time);
return format_time;
}
二. //获取视频/音频文件的总时长
#pragma mark -- 获取视频/音频文件的总时长
- (CGFloat)getFileDuration:(NSURL*)URL {
NSDictionary *opts = [NSDictionary dictionaryWithObject:[NSNumber numberWithBool:NO] forKey:AVURLAssetPreferPreciseDurationAndTimingKey];
AVURLAsset *asset = [AVURLAsset URLAssetWithURL:URL options:opts];
CMTime duration = asset.duration;
float durationSeconds = CMTimeGetSeconds(duration);
return durationSeconds;
}
网友评论