简体   繁体   English

在背景中播放的音频不适用于iOS模拟器

[英]Audio playing in background not working in iOS Simulator

I've seen lots of questions about playing audio in the background. 我已经看到很多关于在后台播放音频的问题。 These questions often ask why the audio plays in the background of the simulator, yet the device simply wouldn't. 这些问题经常会问为什么音频在模拟器的背景中播放,但设备根本不会。

In my case, it's reversed. 在我的情况下,它是相反的。

When I tested my sample app in my iPad, it worked perfectly. 当我在iPad上测试我的示例应用程序时,它运行得很好。 However, when I began testing in the simulator, it simply wouldn't continue playing in the background. 但是,当我开始在模拟器中进行测试时,它根本不会继续在后台播放。

Here are the codes I used: 以下是我使用的代码:

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];

Can anyone tell me why this won't work? 谁能告诉我为什么这不起作用? Is it a bug or something? 这是一个bug还是什么?

iOS模拟器afaik不支持背景音频。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM