I am creating an application using PhoneGap that should play local .mp3 files even if the phone is locked / standby. The sound player is built in HTML5 and works great, but the music stops when I close the application or turn off the phone.
I tried following the answer provided in this UIWebView link : HTML5 audio files in iOS 6 when the application enters the wallpaper
But no luck ...
I made the import code at the top with other import functions. And I also included the scope of AVFoundation in my goal.
This is what the code looks like in AppDelegate.m
- (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions { AVAudioSession *audioSession = [AVAudioSession sharedInstance]; BOOL ok; NSError *setCategoryError = nil; ok = [audioSession setCategory:AVAudioSessionCategoryPlayback error:&setCategoryError]; if (!ok) { NSLog(@"%s setCategoryError=%@", __PRETTY_FUNCTION__, setCategoryError); }
I tried in the simulator and on the iPhone 5.
Can anybody help?
source share