This question is not a duplicated post of this one UIWebView: HTML5 audio pauses in iOS 6 when app enters background
I can access to the track from the control center but the audio is stopped. How avoid the pause state, or how replay the track in the background thread?
All my code is here. You can paste the code in the AppDelegate of a new empty ios app
I's does not work, it's appear in the control center, but music is paused when the app enter in 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;
}
I tried your example code and the url gave a 404. I tried the following url and background mode worked as expected. http://hpr.dogphilosophy.net/test/
When I disabled background audio the background audio paused as expected. I have included the three different ways to enable background audio.
Long story short, you should confirm in your plist that background audio is really enabled. If you still can't get it, post more code.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With