【发布时间】:2014-01-27 01:09:50
【问题描述】:
这个问题不是这个UIWebView: HTML5 audio pauses in iOS 6 when app enters background的重复帖子
我可以从控制中心访问曲目,但音频已停止。 如何避免暂停状态,或者如何在后台线程中重播曲目?
我所有的代码都在这里。您可以将代码粘贴到新的空 ios 应用的 AppDelegate 中
- 添加 AVFoundation 框架
- 启用背景音频
-
我的不工作,出现在控制中心,但是当应用进入后台时音乐暂停!
#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; }
【问题讨论】:
-
你找到答案了吗?我也有同样的问题。
标签: ios audio ios7 youtube html5-audio