Skip to content

Commit

Permalink
Add muted and playsinline attributes (#2124)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
lucaswillering authored and rhukster committed Aug 9, 2018
1 parent 3cee535 commit c84983a
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions system/src/Grav/Common/Page/Medium/VideoMedium.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,40 @@ public function autoplay($status = false)
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.
*
Expand Down

0 comments on commit c84983a

Please sign in to comment.