AVAudioPlayer.duration не равно AVURLAsset.duration - PullRequest
0 голосов
/ 31 мая 2018

Я записываю аудиофайл в формате AVAudioEngin, с внешним форматом:

@{ 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?

1 Ответ

0 голосов
/ 31 мая 2018

Я вижу некоторые варианты на AVAsset.h, о свойстве duration.как показано ниже: 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. это говорит о том, что когда обеспечиваетPreciseDurationAndTiming НЕТ, длительность не совсем правильная, вы должны установить для providePreciseDurationAndTiming значение ДА, просто попробуйте.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...