我看到很多关于在后台播放音频的问题。这些问题通常会问为什么音频会在模拟器的后台播放,而设备却不会。
就我而言,情况正好相反。
当我在 iPad 上测试我的示例应用程序时,它运行良好。但是,当我开始在模拟器中进行测试时,它根本不会在后台继续播放。
以下是我使用的代码:
NSURL *url = [NSURL URLWithString:firstSong];
audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:nil];
[audioPlayer setNumberOfLoops:-1];
[audioPlayer setCurrentTime:0];
[[AVAudioSession sharedInstance]setCategory:AVAudioSessionCategoryPlayback error:nil];
[[AVAudioSession sharedInstance]setDelegate:self];
[[AVAudioSession sharedInstance] setActive:YES error:nil];
[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
[self becomeFirstResponder];
[audioPlayer play];
谁能告诉我为什么这不起作用?是bug还是什么?
最佳答案
iOS Simulator afaik 不支持背景音频。
关于ios - 在后台播放的音频在 iOS 模拟器中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12796157/