AVAudioPlayer 获取语音的长度(时间)

 

 

 

#pragma mark - 获取音频文件时长   aFilePath:语音文件的路径

- (NSString *)getVoiceFileInfoByPath:(NSString *)aFilePath{

    

    NSString *path = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)[0];

    NSString *info = [[NSString alloc]init];

    self.recordFilePath = [path stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.wav",aFilePath]];

    AVAudioPlayer *play = [[AVAudioPlayer alloc]initWithContentsOfURL:[NSURL URLWithString:self.recordFilePath] error:nil];

    info = [info stringByAppendingFormat:@"%0.0f",play.duration];

    

    return info;

}

原文地址:https://www.cnblogs.com/qwer-BHS/p/5315557.html