同时演奏两个AVPlayer音频文件时,音频故障 [英] Audio glitch when playing two AVPlayer audio files simultaneously
问题描述
我有一个iOS应用程序可以播放一个AVPlayer背景配乐和上面播放其他声音片段与第二AVPlayer。 (声音片段都是从网上流式传输,因此要求对AVPlayer)。问题是,第二AVPlayer开始播放时,它会导致后台AVPlayer停一秒钟,类似于在此评论中描述的一小部分:
I have an iOS app that plays a background soundtrack with one AVPlayer and plays other sound clips "on top" with a second AVPlayer. (The sound clips are streamed from the Internet, hence the requirement for AVPlayer.) The problem is that when the second AVPlayer starts playing, it causes the background AVPlayer to stop for a fraction of a second, similar to what's described in this comment:
<一个href=\"http://stackoverflow.com/questions/6193844/play-multiple-audio-files-with-avplayer#comment7213305_6193844\">Play多个音频文件与AVPlayer
我是preparing音频剪辑此方法:
I am preparing the audio clips with this method:
- (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]];
}
...然后调用 [播放器播放];
时,我想听到的每个声音
...and then invoking [player play];
when I want to hear each sound.
有什么我需要做的,当我设置音频会话或AVPlayer的每个实例,使声音不融合的故障?
推荐答案
这可能是因为该软件连接codeR踢中的结果,你会在内存中看到pretty大穗作为软件EN codeR试图播放第二个声音片段。看看苹果的文档节的iOS硬件和软件音频codeCS
<一href=\"http://developer.apple.com/library/ios/#DOCUMENTATION/AudioVideo/Conceptual/MultimediaPG/UsingAudio/UsingAudio.html\"相对=nofollow title=\"UsingAudio\">http://developer.apple.com/library/ios/#DOCUMENTATION/AudioVideo/Conceptual/MultimediaPG/UsingAudio/UsingAudio.html
This is probably as a result of the software encoder kicking in. You'll see a pretty big spike in memory as the software encoder attempts to play the second sound clip. Take a look at the apple docs section "iOS Hardware and Software Audio Codecs" http://developer.apple.com/library/ios/#DOCUMENTATION/AudioVideo/Conceptual/MultimediaPG/UsingAudio/UsingAudio.html
当使用硬件辅助解码,设备可以播放只在一个时间支持的格式之一的单个实例。
"When using hardware-assisted decoding, the device can play only a single instance of one of the supported formats at a time."
也...中扮演多种声音有最佳的性能,或者有效地播放声音而iPod在后台播放,使用线性PCM(uncom pressed)或IMA4(COM pressed)音频。
Also... "To play multiple sounds with best performance, or to efficiently play sounds while the iPod is playing in the background, use linear PCM (uncompressed) or IMA4 (compressed) audio."
如果您有媒体codeCS可以提供别无选择,看看在AudioUnit框架,以获得更无缝的混合。特别是音频混合器(MixerHost)在<一个href=\"http://developer.apple.com/library/ios/#sample$c$c/MixerHost/Introduction/Intro.html#//apple_ref/doc/uid/DTS40010210\" rel=\"nofollow\">http://developer.apple.com/library/ios/#sample$c$c/MixerHost/Introduction/Intro.html#//apple_ref/doc/uid/DTS40010210
If you have no choice in the media codecs you can provide, take a look at the AudioUnit framework to get a more seamless mixing. In particular the "Audio Mixer (MixerHost)" at http://developer.apple.com/library/ios/#samplecode/MixerHost/Introduction/Intro.html#//apple_ref/doc/uid/DTS40010210
这篇关于同时演奏两个AVPlayer音频文件时,音频故障的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!