Cocoa Webview - HTML5全屏无法在OSX上的WebView(WKWebView)中运行

时间:2016-06-23 07:02:59

标签: html5 cocoa video webview fullscreen

我正在尝试使用集成的webkit webview构建一个osx应用程序来显示一个网页。在网页上是html5视频元素,用户应该可以在全屏播放。但是,当我点击“全屏”按钮(一切正常与Safari或Chrome一起工作)时全屏不工作山狮(10.11.4),这是一个错误还是我错过了什么。

HTTML:

<!doctype html>
<html>
<head>
    <title>Full-screen JavaScript Controller</title>
    <style>
        #video-player:-webkit-full-screen {
            width: 100%;
            height: 100%;
            background-color: black;
        }
        #video-player:-webkit-full-screen video {
            width: 100%;
        }
    </style>
    <script type="text/javascript">
        function playPause() {
            var myVideo = document.querySelector('video');
            if (myVideo.paused)
                myVideo.play();
            else
                myVideo.pause();
         }
        function goFullscreen() {
            var myPlayer = document.getElementById('video-player');
            myPlayer.webkitRequestFullscreen();
        }
    </script>
</head>
<body>
    <div id="video-player">
        <video src="http://www.quirksmode.org/html5/videos/big_buck_bunny.mp4"></video>
        <p><a href="javascript:playPause();">Play/Pause</a></p>
        <a href="javascript:goFullscreen();">Full-screen</a>
    </div>
</body>
<body>
</body>
</html>

AppDelegate.m:

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
    NSView* contentView = self.window.contentView;
    WebView* webview = [[WebView alloc]initWithFrame:contentView.bounds];
    NSURL* htmlPath = [NSURL fileURLWithPath:@"fullscreenTest_path/fullscreenTest.html"];
    NSString* data = [NSString stringWithContentsOfFile:[htmlPath path] encoding:NSUTF8StringEncoding error:nil];
    [[webview mainFrame]loadHTMLString:data baseURL:nil];
    [contentView addSubview:webview];
}

0 个答案:

没有答案