音频文件如果是录音是录音的时长即为音频长度,有的时候需要获取一个完成音频文件的长度,判断方法如下:
- (float)audioSoundDuration:(NSURL *)fileUrl {
NSDictionary *options = @{AVURLAssetPreferPreciseDurationAndTimingKey: @YES};
AVURLAsset *audioAsset = [AVURLAsset URLAssetWithURL:fileUrl options:options];
CMTime audioDuration = audioAsset.duration;
float audioDurationSeconds = CMTimeGetSeconds(audioDuration);
return audioDurationSeconds;
}