Please copy vendor/magento/module-catalog/view/frontend/templates/product/list.phtml to your custom theme. app/design/frontend/package/theme/Magento_Catalog/templates/product/list.phtml
<?php
$video = false;
$galleryImages = $this->helper('Your\Module\Helper\Data')->getMediaGalleryImages($_product);
if ($galleryImages) {
foreach ($galleryImages as $primage) {
$imageData = $primage->getData();
// Check media type
if (isset($imageData['media_type']) && $imageData['media_type'] == 'external-video') {
$video = true;
if (strpos($imageData['video_url'], 'youtube.com') !== false) {
echo preg_replace("/\s*[a-zA-Z\/\/:\.]*youtube.com\/watch\?v=([a-zA-Z0-9\-_]+)([a-zA-Z0-9\/\*\-\_\?\&\;\%\=\.]*)/i","<iframe width=\"240\" height=\"300\" src=\"//www.youtube.com/embed/$1\" frameborder=\"0\" allowfullscreen></iframe>", $imageData['video_url']);
}elseif(strpos($imageData['video_url'], 'vimeo.com') !== false){
echo "<iframe width=\"240\" height=\"300\" src=".$imageData['video_url']." frameborder=\"0\" allowfullscreen></iframe>";
}
}
}
}
?>
<?php if(!$video){ ?>
<?= $productImage->toHtml() ?>
<?php } ?>