iOS获取音频或者视频是时间长度

AVURLAsset* audioAsset =[AVURLAssetURLAssetWithURL:audioFileURL options:nil];

CMTime audioDuration = audioAsset.duration;

float audioDurationSeconds =CMTimeGetSeconds(audioDuration);


Note that AVFoundation is designed as a heavily asynchronous framework in order to improve performance and the
overall user experience. Even performing simple tasks such as querying a media file's duration can take a long period
of time which would cause your application to hang. You should use the AVAsynchronousKeyValueLoading protocol to asynchronously
load the duration of the song, and then update your UI in the completion handler block.

你可能感兴趣的:(iOS)