我有一个iOS应用程序,播放一个AVPlayer的背景音轨,并播放其他声音剪辑"在顶部"与第二个AVPlayer.(声音片段是从互联网流式传输的,因此需要AVPlayer.)问题是当第二个AVPlayer开始播放时,它会导致后台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]];
}
Run Code Online (Sandbox Code Playgroud)
......然后[player play];在我想听到每个声音的时候调用.
当我设置音频会话或AVPlayer的每个实例时,我需要做些什么,以便声音在没有故障的情况下融合?