Support

Account

Home Forums Front-end Issues Ombed not autoplaying youtube video

Solving

Ombed not autoplaying youtube video

    • rudtek

    • May 19, 2020 at 9:06 am

    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.

    • rudtek

    • May 20, 2020 at 1:10 am

    this makes sense, but the videos are from youtube and don’t have sound.

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.

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.