1

I am trying to mute a video that is playing as a intro-background on my website. I have all the attributes I need, but I can't figure out how to mute the sound. Thoughts?

// get iframe HTML
$iframe = get_field('slider_video');


// use preg_match to find iframe src
preg_match('/src="(.+?)"/', $iframe, $matches);
$src = $matches[1];


// add extra params to iframe src
$params = array(
'controls'    => 0,
'hd'        => 1,
'autohide'    => 1,
'autoplay' => 1,
'showinfo' => 0
);

$new_src = add_query_arg($params, $src);

$iframe = str_replace($src, $new_src, $iframe);


// add extra attributes to iframe html
$attributes = 'frameborder="0"';

$iframe = str_replace('></iframe>', ' ' . $attributes . '></iframe>',      $iframe);


// echo $iframe
echo $iframe;

?>
<?php endif; ?>
toolbox3
  • 116
  • 9

1 Answers1

0

Looks like you're using Youtube? If so, it appears you'll need to use Javascript to accomplish this. See the accepted answer here:

YouTube: How to present embed video with sound muted

Basically, you'll need to run a script on page load that selects the iframe by ID and run the .mute() method on it.

Community
  • 1
  • 1
Greg Burkett
  • 1,808
  • 1
  • 9
  • 13