1

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?

Anna Fortuna
  • 1,071
  • 2
  • 17
  • 33

1 Answers1

3

Background audio is not supported in iOS Simulator afaik.

Enzo Tran
  • 5,750
  • 6
  • 31
  • 36
  • Background audio is working on simulator with xcode 5.1.1 (not sure when it started working though) – samsam May 15 '14 at 15:02
  • I have xcode 5.1 and it is not working. So I assume that 5.1.1 is the first version of simulator with working background audio. – Borzh Feb 09 '15 at 14:06