我正在尝试根据发送给AVPlayer的速率更改AVPlayerItem的音频音调。
为此,我正在使用指定' AVAudioTimePitchAlgorithmVarispeed'的AVAsset初始化AVPlayerItem,如下所示:
AVPlayerItem *nPlayerItem = [AVPlayerItem playerItemWithAsset:asset];
[nPlayerItem setAudioTimePitchAlgorithm:AVAudioTimePitchAlgorithmVarispeed];
然后我将playerItem附加到AVPlayer,但是当我将AVPlayer的速率设置为小于1或大于1时,音高不会改变。相反,AVPlayerItem使用' AVAudioTimePitchAlgorithmSpectral'算法并不尊重我指定的算法。我的目标是10.9,并建立10.9。根据文档,此功能从10.9开始提供。
答案 0 :(得分:1)
我解决了我的问题:1)将playerItem添加到AVPlayer 2)设置玩家项目状态的键值观察(KVO):
- (void)observeValueForKeyPath:(NSString *)keyPath
ofObject:(id)object
change:(NSDictionary *)change
context:(void *)context {
if ([object isKindOfClass:[AVPlayerItem class]] && [keyPath isEqualToString:@"status"]) {
AVPlayerItem *nPlayerItem = (AVPlayerItem *)object;
if([nPlayerItem status] == AVPlayerItemStatusReadyToPlay){
[nPlayerItem setAudioTimePitchAlgorithm:AVAudioTimePitchAlgorithmVarispeed];
}
}
}
只有在playerItem达到状态' AVPlayerItemStatusReadyToPlay'后,才能在playerItems的audioTimePitchAlgorithm上成功设置AVAudioTimePitchAlgorithmVarispeed。