美文网首页
ios 获取音频时长

ios 获取音频时长

作者: 筱贰笔 | 来源:发表于2017-08-29 14:06 被阅读146次

    用来备份,方便自己使用,需要的拿去

    直接上代码,自己看着办😎 也可以选择去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

    相关文章

      网友评论

          本文标题:ios 获取音频时长

          本文链接:https://www.haomeiwen.com/subject/iqpodxtx.html