最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

swift - Enable Picture-in-Picture for WKWebView on macOS - Stack Overflow

programmeradmin0浏览0评论

On iOS, I can set allowsPictureInPictureMediaPlayback of a WKWebViewConfiguration to true to enable Picture-in-Picture. According to the documentation, this property isn't available on macOS.

Is there any way to enable Picture-in-Picture with a WKWebView on macOS?

On iOS, I can set allowsPictureInPictureMediaPlayback of a WKWebViewConfiguration to true to enable Picture-in-Picture. According to the documentation, this property isn't available on macOS.

Is there any way to enable Picture-in-Picture with a WKWebView on macOS?

Share Improve this question asked Mar 12 at 15:43 fer0nfer0n 1,1831 gold badge12 silver badges31 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

I ran into this same issue a while back, and yeah, it’s a bit of a pain that macOS doesn’t have the allowsPictureInPictureMediaPlayback property like iOS does for WKWebView. The Apple docs make it pretty clear it’s iOS-only, so we’ve got to get creative.

From what I’ve dug up, there’s no direct built-in way to enable Picture-in-Picture (PiP) in WKWebView on macOS, but you can lean on the HTML5 Picture-in-Picture API. If your web content supports it (think videoElement.requestPictureInPicture() in JavaScript), it should work in WKWebView—kinda like how it does in Safari. I’ve tested this with some basic video pages, and it’s solid when the stars align. Check out MDN’s docs for the nitty-gritty on that.

Now, here’s the catch: if you’re building for the Mac App Store, sandboxing can throw a wrench in things. Some folks have tried using the com.apple.PIPAgent entitlement to force PiP—there’s chatter about it on Apple’s forums—but Apple’s rejected apps for it unless it’s super justified. So, if you’re not going App Store, you might experiment with that, but it’s dicey.

Another workaround I’ve seen is pulling the video URL out of the WKWebView and playing it with AVPlayer, which does support PiP on macOS. It’s a hassle, though, and not always practical if the video’s buried in tricky web code. Kodeco’s got a guide that touches on this if you’re curious.

Honestly, macOS just doesn’t seem as PiP-friendly for web stuff as iOS. If you control the webpage, the HTML5 API is your best shot. Otherwise, you might be stuck tweaking things case-by-case or waiting for Apple to throw us a bone in a future update. Anyone else found a slicker way around this?

Key Citations

  1. Apple WKWebViewConfiguration Docs

  2. MDN Picture-in-Picture API

  3. Apple Developer Forums

  4. Kodeco PiP Guide

发布评论

评论列表(0)

  1. 暂无评论