【发布时间】:2023-04-02 19:58:01
【问题描述】:
当我的应用程序在前台和后台时,我必须提供音频反馈。但是当应用程序进入后台时,听不到音频反馈。在 info.plist 中,我已将后台模式设置为 App 使用 AirPlay 播放音频或流式传输音频/视频并使用以下内容,但当应用程序进入后台且听不到音频时,不会调用 audioPlayerDidFinishPlaying 委托。
AVAudioPlayer *sound = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:&err];
sound.delegate = self;
///Fixed the issue No audible feedback when main audio is silent
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:nil];
[[AVAudioSession sharedInstance] setActive: YES error: nil];
// This is necessary if you want to play a sequence of songs, otherwise your app will be
// killed after the first one finishes.
[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
[soundQueue addObject:sound];
【问题讨论】:
标签: ios iphone objective-c avaudioplayer