用来备份,方便自己使用,需要的拿去
直接上代码,自己看着办😎 也可以选择去GitHub下载☞ZQAudioLengthTool
ZQAudioLengthTool.h
#import@interface ZQAudioLengthTool : NSObject
+ (NSUInteger)durationWithVideo:(NSURL *)videoUrl;
@end
ZQAudioLengthTool.m
#import "ZQAudioLengthTool.h"
@implementation ZQAudioLengthTool
+ (NSUInteger)durationWithVideo:(NSURL *)videoUrl
{
AVURLAsset*audioAsset=[AVURLAsset URLAssetWithURL:videoUrl options:nil];
CMTime audioDuration=audioAsset.duration;
float audioDurationSeconds=CMTimeGetSeconds(audioDuration);
if (audioDurationSeconds>0) {
NSUInteger interValue = (audioDurationSeconds *10+5)/10;
return interValue;
}
return 0;
}
@end