我有一個iOS應用程序,它可以播放一個AVPlayer的背景音軌,並在第二個AVPlayer上播放其他聲音片段。 (聲音剪輯從互聯網流出,因此需要AVPlayer。)問題是,當第二個AVPlayer開始播放時,它會導致後臺AVPlayer停止幾分之一秒,這與本評論中描述的內容類似:同時播放兩個AVPlayer音頻文件時的音頻故障
Play multiple Audio Files with AVPlayer
我準備的音頻剪輯用這種方法:
- (void)prepareAudio:(NSURL *)assetURL {
asset = [AVURLAsset URLAssetWithURL:assetURL options:nil];
playerItem = [AVPlayerItem playerItemWithAsset:asset];
[player replaceCurrentItemWithPlayerItem:playerItem];
[playerItem addObserver:self forKeyPath:@"playbackBufferEmpty" options:NSKeyValueObservingOptionNew context:nil];
[playerItem addObserver:self forKeyPath:@"playbackLikelyToKeepUp" options:NSKeyValueObservingOptionNew context:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(playerItemDidReachEnd:)
name:AVPlayerItemDidPlayToEndTimeNotification
object:[player currentItem]];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(playerItemFailedToReachEnd:)
name:AVPlayerItemFailedToPlayToEndTimeNotification
object:[player currentItem]];
}
...,然後調用[player play];
當I W螞蟻聽到每一個聲音。
有什麼我需要做的,當我設置音頻會話或AVPlayer的每個實例,使聲音不融合的故障?
這不可能。我已經做了一些使用直接PCM未壓縮文件的實驗,問題依然存在。這就是說,它似乎與AVMutableAudioMix的應用有關。無論什麼時候應用,就是在發生漏接時。 –