- Issue created by @holybiber
- 🇩🇪Germany marcoka
Info for autoplay of youtube-videos taken from googles docs
To make an embedded video autoplay, add "&autoplay=1" to the video's embed code right after the video ID (the series of letters that follows "embed/"). Embedded videos that are autoplayed don't increment video views.
- 🇩🇪Germany marcoka
Ok this is how you can achieve that.
I also switched the domain to cookieless "youtube-nocookie.com" in this example- pd7_radix: is the themes name
- This code goes to the pd7_radix.theme
- Only works for oembed
function pd7_radix_preprocess_media_oembed_iframe(&$variables) {
// Pull iframe tag
$iFrame = $variables['media']->__toString();
// Switch domain to the youtube nocookie domain.
if (stripos($iFrame, 'youtube.com') !== false){
$newFrame = str_replace('youtube.com/', 'youtube-nocookie.com/', $iFrame);
$autoplay = str_replace('?feature=oembed', '?feature=oembed&autoplay=1', $iFrame);
$variables['media'] = IFrameMarkup::create($autoplay);
}
}Using that the video will autoplay when you click ok.
- 🇩🇪Germany marcoka
I did some experiments with that code. It seems sometimes the video is still loaded even if the user does not click ok.
In that case you can "hear" it because its on autoplay.