我正在尝试在收到远程通知时自动播放声音文件(这不是我的应用程序包的一部分,也不是通知声音)。我希望在收到通知时无论应用程序处于前台还是后台都将发生这种情况。
我正在使用Amazing Audio Engine作为核心音频库的包装。在我的App Delegate中,didReceiveRemoteNotification创建一个Audio Controller并添加AEAudioFilePlayer到其中,如下所示:
NSURL *file = [NSURL fileURLWithPath:sourceFilePath];
AEAudioFilePlayer *notificationPlayer = [AEAudioFilePlayer audioFilePlayerWithURL:file
audioController:_notificationController
error:NULL];
notificationPlayer.completionBlock = ^{
// Remove self from channel list after playback is complete
[_notificationController removeChannels:[NSArray
arrayWithObjects:notificationPlayer,nil]] ;
};
[_notificationController addChannels:[NSArray
arrayWithObjects:notificationPlayer,nil]];
Run Code Online (Sandbox Code Playgroud)
但是,声音无法播放!我的日志显示以下错误:
2014-08-18 06:21:28.003 MyApp[394:60b] TAAE: Setting audio session category to AVAudioSessionCategoryPlayback
2014-08-18 06:21:28.019 MyApp[394:60b] Couldn't activate audio session: Error Domain=NSOSStatusErrorDomain Code=561015905 "The operation couldn’t be completed. (OSStatus error 561015905.)"
2014-08-18 06:21:28.024 MyApp[394:60b] TAAE: Audio session initialized (audio …Run Code Online (Sandbox Code Playgroud)