UIMoviePlayerControllerDidEnterFullscreenNotification在iOS8中不起作用 [英] UIMoviePlayerControllerDidEnterFullscreenNotification doesn't work in iOS8
问题描述
我正在使用 UIWebView
使用iFrame播放YouTube视频。
我正在使用 UIMoviePlayerControllerDidEnterFullscreenNotification
将youtube屏幕检测到全屏。
如下代码:
I am using UIWebView
to play a youtube video with iFrame.
I am using UIMoviePlayerControllerDidEnterFullscreenNotification
to detect youtube screen into fullscreen.
Like below code :
[[NSNotificationCenter defaultCenter] addObserver: self
selector: @selector(myMovieEnterFullScreen:)
name: @"UIMoviePlayerControllerDidEnterFullscreenNotification"
object: nil];
它适用于iOS7。
但我尝试在iOS8中运行它。
它不起作用。
我认为通知名称已被更改。
有没有办法在ios8中检测youtube全屏事件?
It works in iOS7.
But I try to run it in iOS8.
It doesn't work.
I think the notification name has be changed.
Has any alternative to detect the youtube fullscreen event in ios8?
推荐答案
markussvensson的实现有一些误报,因为任何UIWindowDidBecomeVisibleNotification都被视为全屏视频播放,但这不是真的。
The implementation by markussvensson has some false alarms, since any UIWindowDidBecomeVisibleNotification is considered as a full screen video playback which is not true.
Selvin的实现AVPlayerItemBecameCurrentNotification可以捕捉电影播放开始,但无法捕捉电影播放停止。
The implementation "AVPlayerItemBecameCurrentNotification" by Selvin can catch movie playback start, but cannot catch movie playback stop.
所以我结合两种实现,它按预期工作。
So I combined both implementations and it works as expected.
-
将观察者添加到AVPlayerItemBecameCurrentNotification& UIWindowDidBecomeHiddenNotification;
Add observer to both AVPlayerItemBecameCurrentNotification & UIWindowDidBecomeHiddenNotification;
当AVPlayerItemBecameCurrentNotification发生时,设置一个标志;
When AVPlayerItemBecameCurrentNotification happens, set a flag;
当UIWindowDidBecomeHiddenNotification发生时,检查标志是否是视频停止播放事件。
When UIWindowDidBecomeHiddenNotification happens, check the flag to see if it is a "video stop playing event".
BTW,AVPlayerItemBecameCurrentNotification未记录,可能为下一个iOS主要版本打破。
BTW, AVPlayerItemBecameCurrentNotification is undocumented and might be broken for the next iOS major release.
这篇关于UIMoviePlayerControllerDidEnterFullscreenNotification在iOS8中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!