iOS计算视频长度
程序员文章站
2024-02-26 18:07:10
...
添加#import <AVFoundation/AVFoundation.h>
头文件
//计算视频长度 (秒)
NSURL *url = [NSURL URLWithString:@"http://wvideo.spriteapp.cn/video/2016/0328/56f8ec01d9bfe_wpd.mp4"];
NSDictionary *opts = [NSDictionary dictionaryWithObject:[NSNumber numberWithBool:NO] forKey:AVURLAssetPreferPreciseDurationAndTimingKey];
AVURLAsset *urlAsset = [AVURLAsset URLAssetWithURL:url options:opts];
NSInteger totalSecond = urlAsset.duration.value / urlAsset.duration.timescale;
NSLog(@"计算视频长度 = %ld",(long)totalSecond);
下一篇: Java中map遍历方式的选择问题详解