This question is not a duplicate of this UIWebView post : HTML5 audio pause in iOS 6 when the app enters the wallpaper
I can access the track from the control center, but the sound is stopped. How to avoid a pause state or how to play a track in a background thread?
All my code is here. You can paste code into AppDelegate from a new empty ios application
- Add AVFoundation Structure
- Enable background audio
I donโt work, it appears in the control center, but the music pauses when the application enters Background!
#import "AppDelegate.h" #import <AVFoundation/AVFoundation.h> @implementation AppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; // Override point for customization after application launch. AVAudioSession *audioSession = [AVAudioSession sharedInstance]; BOOL ok; NSError *setCategoryError = nil; ok = [audioSession setCategory:AVAudioSessionCategoryPlayback error:&setCategoryError]; if (!ok) { NSLog(@"%s setCategoryError=%@", __PRETTY_FUNCTION__, setCategoryError); } UIViewController *vc = [[UIViewController alloc] init]; UINavigationController* nav = [[UINavigationController alloc] initWithRootViewController: vc]; self.window.rootViewController = nav; //WEBVIEW UIWebView *myWeb = [[UIWebView alloc] initWithFrame:CGRectMake(0, 200, 320, vc.view.frame.size.height)]; myWeb.mediaPlaybackRequiresUserAction = NO; myWeb.allowsInlineMediaPlayback = YES; [vc.view addSubview:myWeb]; NSURLRequest *request = [[NSURLRequest alloc] initWithURL: [NSURL URLWithString: @"http://www.romito.fr/public/inlineHTML5/"]]; [myWeb loadRequest: request]; self.window.backgroundColor = [UIColor whiteColor]; [self.window makeKeyAndVisible]; return YES; }
source share