From c84983ad5bced37c3083db3f704e668ddb54384a Mon Sep 17 00:00:00 2001 From: lucaswillering Date: Thu, 9 Aug 2018 23:32:53 +0200 Subject: [PATCH] Add muted and playsinline attributes (#2124) Fixes: #2099 To be able to add videos to sites that behave as GIFs, two attributes are needed for the videos to be properly handled on iOS and in Chrome: muted and playsinline. Muted Chrome only allows videos to autoplay when the contain the muted attribute. Non-muted videos will not autoplay unless the user has interacted with the site. More details here: https://developers.google.com/web/updates/2017/09/autoplay-policy-changes#new-behaviors Playsinline The playsinline attribute allows developers to specify videos on iPhone should play inline and not automatically enter fullscreen mode when playback begins. More details here: https://developers.google.com/web/updates/2017/09/autoplay-policy-changes#new-behaviors --- .../Grav/Common/Page/Medium/VideoMedium.php | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/system/src/Grav/Common/Page/Medium/VideoMedium.php b/system/src/Grav/Common/Page/Medium/VideoMedium.php index b3c8eed85..23271bf35 100644 --- a/system/src/Grav/Common/Page/Medium/VideoMedium.php +++ b/system/src/Grav/Common/Page/Medium/VideoMedium.php @@ -94,6 +94,40 @@ class VideoMedium extends Medium return $this; } + /** + * Allows to set the playsinline attribute + * + * @param bool $status + * @return $this + */ + public function playsinline($status = false) + { + if($status) { + $this->attributes['playsinline'] = true; + } else { + unset($this->attributes['playsinline']); + } + + return $this; + } + + /** + * Allows to set the muted attribute + * + * @param bool $status + * @return $this + */ + public function muted($status = false) + { + if($status) { + $this->attributes['muted'] = true; + } else { + unset($this->attributes['muted']); + } + + return $this; + } + /** * Reset medium. *