2017년 1월 12일 목요일

비디오파일 duration 가져오기

- (NSString *)getVideoFileDuration:(NSString *)fileName {
    NSString *videoFilePath = [[self localVideoStorageDir] stringByAppendingPathComponent:fileName];
    NSURL *url = [NSURL fileURLWithPath:videoFilePath];
    AVURLAsset *sourceAsset = [AVURLAsset URLAssetWithURL:url options:nil];
    CMTime duration = sourceAsset.duration;
    NSInteger seconds = (int)CMTimeGetSeconds(duration);
    
    NSDate* date = [NSDate dateWithTimeIntervalSince1970:seconds];
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setTimeZone:[NSTimeZone timeZoneWithName:@"UTC"]];
    if (seconds >= 360) {
        [dateFormatter setDateFormat:@"HH:mm:ss"];
    } else{
        [dateFormatter setDateFormat:@"mm:ss"];
    }
    NSString* result = [dateFormatter stringFromDate:date];
    return result;

}

댓글 없음:

댓글 쓰기