Audio playing in background not working in iOS Simulator

空扰寡人 提交于 2019-12-11 07:56:42

问题


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. 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?


回答1:


Background audio is not supported in iOS Simulator afaik.



来源:https://stackoverflow.com/questions/12796157/audio-playing-in-background-not-working-in-ios-simulator

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!