WebView: Configure WKWebView to support inline media playback on iPhones - #15029
Conversation
|
You can trigger an installable build for these changes by visiting CircleCI here. |
|
You can trigger optional UI/connected tests for these changes by visiting CircleCI here. |
|
I gave this a try, it seems to be working great! 🎉 I checked that this works both from the Reader and when viewing a post with a story from the post list (in that case there's no autoplay, the post opens and you tap the story to open it). The inline playing works great. I think this PR coupled with a fix for broken autoplay for videos with sound makes for a pretty solid v1 for story playback from WPiOS (leaving just fullscreen support from #15026, which is not critical). Tug actually just added a fix for autoplay in Automattic/jetpack#16852 🎉 You can test this with this feature by following my sandbox site (I'll share the link with you). Note that there's currently an issue with unmuting, which we can hopefully get fixed soon. |
|
Cool. :) Particularly interested to hear from @leandroalonso (who has some background already) and @emilylaguna @yaelirub and @mbshakti who have all been more invested in the reader side of things lately. Depending on the consensus we can expand this proof of concept for special story handling or not. |
|
@aerych the Reader uses it's own I played with that when I was implementing the webView and I wasn't able to make the private func configureWebView() {
webView.navigationDelegate = self
webView.configuration.allowsInlineMediaPlayback = true
}I tried with both VideoPress and YouTube and when you tap play it goes to fullscreen. I wonder that maybe this is due to the content of the webview being loaded locally (using |
I should have guessed :)
WKWebView configuration can't be modified after the WKWebView is created. Guessing that might be the issue? Per the docs:
If the reader is creating the WKWebView via a Storyboard (I haven't looked to see) we'd need to change that to be instantiated programmatically -- assuming we want the behavior to be consistent everywhere. (Honestly not sure that we do.) |
|
Hmmm, that might be the issue then! I'll check again, thanks for the heads up! |
|
@aerych I changed in the Storyboard (there's an inline playback option) and the behavior is the same: https://d.pr/v/9Mh5vw I wonder if maybe that's how Youtube/VideoPress behaves? |
I think it depends on if the video specifies the "playsinline" attribute. I made a test post with some video tags and some youtube embeds. Youtube doesn't want to play for me (I guess that's what I get for trying to rickroll 😆) but the video from the media library does. And now that I think about it, maybe my original question about setting the WKWebView configuration is moot. The video markup has to specify if it can play inline or not so the experience will be inconsistent regardless. Thoughts? |
|
@aerych Agree! Anyway, I'd keep in the |
|
Sounds like a plan. :) |
|
@aforcier how would you like to proceed? Shall we close this one in favor of one that includes some of the other changes you mentioned? |
Just making sure I understand the outcome of the conversation:
The autoplay fix is all taken care of server-side (@Tug just fixed the remaining issue I mentioned with the unmute button 🙇). That just leaves fullscreen support, which is a nice-to-have but not necessary for v1 (iOS Safari itself doesn't even support it as far as I can tell...). So, I'd say this PR as-is is all we need, and can probably be un-drafted. WDYT @aerych? Also thank you both @leandroalonso @aerych 🙇 |
|
@aforcier you have it exactly, and that sounds good to me. :) |
|
Looks good to me, and working well for opening Stories from the Reader and viewing story posts from the post list. |
|
Thanks all! |
Refs #15026
This PR adds a WKWebViewConfiguration to the WebKitViewController. This allows web-based videos to be played inline on the iPhone if they are coded to do so. This is the default behavior on the iPad, and desired for WPStories regardless of the platform on which they are viewed.
With this change video tags that define the
playsinlineattribute will now play inline on the iPhone and iPad, while video tags that do not specify this attribute will continue to play full screen in the native player.See comments below and the referenced issue for more details.
@aforcier, @leandroalonso would either of you care to review? 😁
To test:
View a WPStory with a video slide. Confirm the video plays inline vs opening the native viewer.
PR submission checklist:
RELEASE-NOTES.txtif necessary.