如何防止UIWebView视频获取远程控制事件 [英] How to prevent UIWebView video from getting remote control events

查看:27
本文介绍了如何防止UIWebView视频获取远程控制事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 iOS 应用中使用 UIWebView 来播放 YouTube 视频,但为了提供原生体验,我使用 UIKit 实现了播放控件.所以 UIWebView 只用于显示视频.

I am using UIWebView in an iOS app to play YouTube videos but to provide native experience, I've implemented playback controls using UIKit. So the UIWebView is only used to display video.

我还实现了 -remoteControlReceivedWithEvent: 以允许从控制中心和耳机上的控制器按钮进行控制.但似乎 UIWebView 会自动处理来自耳机的远程控制事件.这是一个问题,因为当您切换播放/暂停时,我的代码会暂停视频,然后 UIWebView 将再次切换它以播放视频.

I've also implemented -remoteControlReceivedWithEvent: to allow control from Control Center and controller buttons on earphones. But it seems that UIWebView automatically handles remote control events from the earphones. This is a problem because when you toggle play/pause, my code would pause the video and then UIWebView will toggle it again to play the video.

有没有办法防止这种情况发生?

Is there anyway to prevent this from happening?

相关问题是UIWebView 尝试将Now Playing"信息设置为MPNowPlayingInfoCenter,这也是由我的代码完成的.

Related issue is that UIWebView tries to set "Now Playing" information to MPNowPlayingInfoCenter which is also done by my code.

推荐答案

我的应用程序使用 AVAudioPlayer 播放音频时遇到了同样的问题.此应用在播放过程中会在 MPNowPlayingInfoCenter 中显示当前的音频信息.我的要求是在播放器顶部的 web 视图中显示 html5 视频广告(带音频).

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.

首先我只使用 UIWebView 因为我需要支持 iOS7 但我遇到了很多问题,其中之一是 MPNowPlayingInfoCenter 显示广告视频的 url 代替当前本地音频播放.我尝试了几种解决方案,例如 UIWebView 上的 method swizzling,但都没有成功.

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.

我只找到了一种适合我的解决方案:默认使用 WKWebView 而不是 UIWebView 网络容器.HTML5 视频播放将不再与 MPNowPlayingInfoCenter 交互,我还必须支持 iOS7,所以我创建了一个包装类来在 iOS7 和 UIWebView(仍然存在问题)之间切换code>WKWebView 来自 iOS8 和更多.

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.

希望这会有所帮助.

这篇关于如何防止UIWebView视频获取远程控制事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆