Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disabling auto-play in full screen on iOS

The only problem i'm having is that i'm unable to disable playing videos on full screen according to apple documentation this is enabled by default and needs to be set as follows:

webView.configuration.allowsInlineMediaPlayback = true

Which is based on my understanding how it's supposed to be. However this doesn't work and even after configuration right after you press play on video it opens up in native full screen player. I'm using WKWebView.

Apple's Documentation for this

like image 911
Martin Dichtler Avatar asked Jul 03 '18 17:07

Martin Dichtler


2 Answers

I faced with this problem using video tag in web view. I have three videos in the page, and all videos successively played full screen. I solved this problem by

1.Check Inline Playback

enter image description here

2.Add playsinline attribute to video tag

<video src="your_videosrc" autoplay playsinline></video>

Glad someones help :)

like image 140
kazuwombat Avatar answered Sep 28 '22 21:09

kazuwombat


Playing a video inline requires two prerequisites:

  1. Setting the configuration
  2. Providing a correctly formatted link

1. Setting the configuration

The configuration of the WKWebView has needs to be set while initialising. Modifying allowsInlineMediaPlayback at a later point will not work:

let configuration = WKWebViewConfiguration()
configuration.allowsInlineMediaPlayback = true

let webView = WKWebView(frame: CGRect(x: 0, y: 0, width: view.frame.width, height: view.frame.height), configuration: configuration)

view.addSubview(webView)

2. Providing a correctly formatted link

In order for the web view to know that the video should start playing inline the appropriate URL parameter needs to be set.

For this you simply have to append ?playsinline=1.

Example:

webView.load(URLRequest(url: URL(string: "https://www.youtube.com/watch?v=OYbXaqQ3uuo?playsinline=1")!))
like image 32
JP_ Avatar answered Sep 28 '22 23:09

JP_