Testing background audio in the simulator

Posted by Cactuar on Stack Overflow See other posts from Stack Overflow or by Cactuar
Published on 2010-04-24T12:11:57Z Indexed on 2010/04/24 12:13 UTC
Read the original article Hit count: 432

I'm experimenting with the new background audio service in iPhone OS 4.0 but I can't get it to work in the simulator.

According to this page: iPhone Application Programming Guide: Executing Code in the Background it seems that all I have to do is add the a UIBackgroundModes key with an array containing audio to my Info.plist file and the audio my application plays should automatically continue when I switch to another app. I have done this but the audio still pauses as I switch to another app, when I switch back it continues where it left off.

This is the code I'm using to play the sound:

NSURL *url = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/audio.mp3", [[NSBundle mainBundle] resourcePath]]];

NSError *error; audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:&error]; audioPlayer.numberOfLoops = -1;

if (audioPlayer == nil) NSLog(@"%@", [error userInfo]); else [audioPlayer play];

Has anyone gotten this to work? Could it be that it would work on an actual device and it's just a problem with the simulator? I'm a bit hesitant to install 4.0 on my phone since I've heard it's still very buggy. Wish I had another device to use only for development.

© Stack Overflow or respective owner

Related posts about iphone

Related posts about iphone-simulator