使用airplay播放音频时如何减少截止?

ech*_*cho 11 audio objective-c ios airplay apple-tv

当通过AirPlay(使用iOS9.2)从连接到Apple TV的iOS设备播放声音时,声音播放的前一秒左右会被切断.这种不受欢迎的行为不是应用程序特定的,而是系统范围的(例如Apple的官方应用程序也有此错误).

请参阅https://forums.developer.apple.com/thread/28086

是否有audio file可以播放完整的解决方法?例如blank sounds在播放文件之前添加?或改变如何API调用?或者我应该等待Apple正式修复?

Mar*_*kle 0

  1. 当前的任何 iOS 版本似乎都没有出现此问题,因此我的第一个建议是升级。
  2. 如果您必须使用 iOS 9.2,那么我建议播放空白音频文件 2 秒钟,然后启动完整的音频文件。

示例代码:

audioPlayer.actionAtItemEnd = AVPlayerActionAtItemEndNone; 

[[NSNotificationCenter defaultCenter] addObserver:self
                                               selector:@selector(playEnded:)
                                                   name:AVPlayerItemDidPlayToEndTimeNotification
                                                 object:[audioPlayer currentItem]];

- (void)playEnded:(NSNotification *)notification
{
    // Start the full audio file here
}
Run Code Online (Sandbox Code Playgroud)