Trying to get vimeo as a background to work. Here’s my code:
<?php $video = get_field( 'video' );
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(
'playsinline' => 1,
'controls' => 0,
'hd' => 1,
'autoplay' => 1,
'background' => 1,
'loop' => 1,
'byline' => 0,
'title' => 0,
'muted' => 1
);
$new_src = add_query_arg($params, $src);
$video = str_replace($src, $new_src, $video);
// add extra attributes to iframe html
$attributes = 'frameborder="0" autoplay muted loop playsinline webkit-playsinline';
$video = str_replace('></iframe>', ' ' . $attributes . '></iframe>', $video);
}
echo '<div class="video-embed">', $video, '</div>';
} ?>
Works on some browsers but not on iOS. I think I need <video> tag instead <iframe> for videos to work inline? Any ideas?
Ok nevermind it worked in the end! Probably tried it without mute