Home › Forums › Front-end Issues › Ombed not autoplaying youtube video
I am trying to get my videos to auto play on my page. I have created a field called ‘turntable_embed’ as subfield of ‘event_turntable’.
Here is my display code:
<?php
if( have_rows('event_turntable') ):?>
<div class="eventRow eventTurntable black" style="background-image:radial-gradient(circle, transparent 0%, #000 40%), url('<?php echo get_stylesheet_directory_uri(); ?>/images/bg-honeycomb.png')"><div class="flexed container centered">
<?php // loop through the rows of data
while ( have_rows('event_turntable') ) : the_row();
// display a sub field value
$video = get_sub_field('turntable_embed');
if ( $video ) {
// Add autoplay functionality to the video code
if ( preg_match('/src="(.+?)"/', $video, $matches) ) {
// Video source URL
$src = $matches[1];
// Add option to hide controls, enable HD, and do autoplay -- depending on provider
$params = array(
'autoplay' => 1
);
$new_src = add_query_arg($params, $src);
$video = str_replace($src, $new_src, $video);
// add extra attributes to iframe html
$attributes = 'frameborder="0"';
$video = str_replace('></iframe>', ' ' . $attributes . '></iframe>', $video);
}
}
echo '<div style="padding: 0 10px;"><div class=" auto embed-container">'.$video.'</div>';
echo '<h3>'.get_sub_field('turntable_title').'</h3></div>';
endwhile;
echo '</div></div>';
else :
// no rows found
endif;
?>
Changing autoplay to 0, they don’t play (as would be expected). When auto play is set to 1 there is a loading bar at the bottom of the that fully loads, but the video doesn’t play automatically.
Any ideas?
This is not something to do with ACF or oEmbed. This is a browser thing. Browsers will no longer autoplay videos that include sound and other things.
https://developers.google.com/web/updates/2017/09/autoplay-policy-changes
It’s bases on what the user does and not what we want to happen.
this makes sense, but the videos are from youtube and don’t have sound.
Yes, autoplay is only allowed when mute is on. User must manually turn off Mute.
Even if videos do not have sound they still must still be set to muted. There isn’t any way for the browser to auto detect if a video has sound or not.
The topic ‘Ombed not autoplaying youtube video’ is closed to new replies.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.