How to prevent UIWebView video from getting remote control events

血红的双手。 提交于 2019-12-05 03:45:52

I encountered same kind of issue with my app which playbacks audio using AVAudioPlayer. This app displays current audio info in MPNowPlayingInfoCenter during playback. My requirement was to display an html5 video advert (with audio) inside a webview on top my player.

First i used only UIWebView as i needed to support iOS7 but i met a lot of issues, one of them was MPNowPlayingInfoCenter that displays url of ad video in place of current native audio playback. I tried several solutions such as method swizzling on UIWebView without any success.

I found only one solution that works for me: use WKWebView by default instead of UIWebView web container. HTML5 video playback will not interact anymore with MPNowPlayingInfoCenter, i had to support also iOS7 so i created a wrapper class to switch between UIWebView (with still the issue) on iOS7 and WKWebView from iOS8 and more.

Hope this helps.

I ran into this question while trying to solve somewhat the reverse problem: I added a UIWebView to an app and remote control events were not working when the UIWeb view was on display, but worked elsewhere in the app. In my case the solution was to add these 3 methods, which are present on all other view controllers in my app, to the controller of my new UIWebView:

- (void) viewDidAppear:(BOOL)animated  {
    [self becomeFirstResponder];
}

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    [self resignFirstResponder];
}

-(void)remoteControlReceivedWithEvent:(UIEvent *)event {
    // Logic to handle remote control events
}

From this, I suspect that you can prevent your UIWebView from handling remote control events by doing one of two things: 1. Include logic in the remoteControlReceivedWithEvent to ignore the remote control events you don't want handled. 2. Have your UIWebView resign being the first responder by calling resignFirstResponder in the viewDidAppear method of the controller.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!