IOS7 - UIWebView: HTML5 audio files pause when application enters background

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; } 
+6
source share
1 answer

I tried your sample code and url gave 404. I tried using the following url and background mode, as expected. http://hpr.dogphilosophy.net/test/

When I turned off the background sound, the background sound paused as expected. I have included three different ways to turn on background sound.

In short, you must confirm in your plist that the background sound is indeed on. If you still cannot get it, write more code.

Enabling background audio via Capabilities

Enabling background audio via plist

Enabling background audio via raw plist

0
source

All Articles