iOS 获取视频时长和大小

来源:互联网 发布:java基础书籍推荐 编辑:程序博客网 时间:2024/05/22 04:24

这里说的视频并不是相册中的视频,而是保存在你app沙盒中的视频文件

//记得导入AVFoundation框架#import <AVFoundation/AVFoundation.h>xxfile.h/** * @method * * @brief 根据路径获取视频时长和大小 * @param path       视频路径 * @return    字典    @"size"--文件大小   @"duration"--视频时长 */- (NSDictionary *)getVideoInfoWithSourcePath:(NSString *)path;xxfile.m- (NSDictionary *)getVideoInfoWithSourcePath:(NSString *)path{    AVURLAsset * asset = [AVURLAsset assetWithURL:[NSURL fileURLWithPath:path]];    CMTime   time = [asset duration];    int seconds = ceil(time.value/time.timescale);    NSInteger   fileSize = [[NSFileManager defaultManager] attributesOfItemAtPath:path error:nil].fileSize;    return @{@"size" : @(fileSize),             @"duration" : @(seconds)};}

最后,如果你为高度计算而烦恼,可参看链接文章
http://blog.csdn.net/mo_mo123/article/details/53701380
如有疑惑欢迎留言区讨论

0 0
原创粉丝点击