我嵌入了一个 iframe 视频,我想检测用户何时退出(点击“完成”)移动 Safari 上的全屏功能,当您点击“播放”时发生。我试过下面的代码:
HTML
<iframe id="video-iframe" src="//player.vimeo.com/video/105953491?title=0&byline=0&portrait=0&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)。有什么想法吗?
最佳答案
在 iOS 8 上,当系统视频播放器接管 iOS 上的 UIWebView
时,应用程序的主窗口会隐藏。监听 View Controller 上的 UIWindowDidBecomeHiddenNotification
和 UIWindowDidBecomeVisibleNotification
通知,以检测用户何时进入和退出全屏播放器:
[[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];
关于javascript - 在 iPhone 上检测 “Done” 以获取 YouTube/Vimeo 视频(退出全屏),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26419135/