我用AVAudioEngin
录制了一个音频文件,格式为out:
@{ AVSampleRateKey:@(44100.0), AVNumberOfChannelsKey: @(1), AVFormatIDKey: @(kAudioFormatMPEG4AAC), }
,
然后我用AVAudioPlayer
回放
self.player = [[AVAudioPlayer alloc] initWithData:[NSData dataWithContentsOfFile:self.outFilePath] error:nil];
NSTimeInterval duration = _player.duration; // 409.73357109834228
AVURLAsset*audioAsset = [AVURLAsset URLAssetWithURL:[NSURL fileURLWithPath:self.outFilePath] options:nil];
CMTime audioDuration = audioAsset.duration;
Float64 seconds = CMTimeGetSeconds(audioDuration); // 429.31374149659865
为什么duration
不等于seconds
我是否遗漏了一些要为AVAudioPlayer
设置的属性
发布于 2018-05-31 17:40:52
我在AVAsset.h上看到了一些关于duration属性的选项。如下所示:如果providesPreciseDurationAndTiming为NO,则说明持续时间不完全正确,您应该将providesPreciseDurationAndTiming设置为Indicates the duration of the asset. If @"providesPreciseDurationAndTiming" is NO, a best-available estimate of the duration is returned. The degree of precision preferred for timing-related properties can be set at initialization time for assets initialized with URLs. See AVURLAssetPreferPreciseDurationAndTimingKey for AVURLAsset below.
,试一试。
https://stackoverflow.com/questions/50620749
复制相似问题