检测iPhone上的“完成”以获取YouTube / Vimeo视频(退出全屏)

时间:2014-10-17 06:29:31

标签: javascript ios youtube youtube-api youtube-iframe-api

我嵌入了iframe视频,我想检测用户何时退出(点击“完成”)移动Safari上的全屏功能,当您点按“播放”时。我尝试了下面的代码:

HTML

<iframe id="video-iframe" src="//player.vimeo.com/video/105953491?title=0&amp;byline=0&amp;portrait=0&amp;api=1" width="100%" height="100%" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>

的JavaScript

document.getElementById("video-iframe").addEventListener("webkitendfullscreen", function(){
  alert("Hello World!");
});

演示:http://jsfiddle.net/p3bLohfk/

但它不起作用(iOS 8.0.2)。有什么想法吗?

1 个答案:

答案 0 :(得分:-1)

在iOS 8上,当系统视频播放器从iOS上的UIWebView接管时,应用程序的主窗口将被隐藏。在视图控制器上收听UIWindowDidBecomeHiddenNotificationUIWindowDidBecomeVisibleNotification通知,以检测用户何时进入和退出全屏播放器:

[[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(videoDidExitFullScreen:)
                                                 name:UIWindowDidBecomeVisibleNotification
                                               object:self.view.window];

[[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(videoDidEnterFullScreen:)
                                                 name:UIWindowDidBecomeHiddenNotification
                                               object:self.view.window];