0

How to display YouTube video as thumbnail image in Magento?

4
0

$videourl is youtube video url and in phtml file you can put this.

Try below code:

<?php 
            $posOfV = strpos($videourl,'?v=');
            if($posOfV === false) 
            {
                $explodeArr = explode("youtu.be/",$videourl);
                $embedId = $explodeArr[1];      
            }
            else 
            {
                $explodeArr = explode("?v=",$videourl);
                $pos = strpos($explodeArr,'&');
                if($pos === false)
                 {
                    $embedId = $explodeArr[1];
                 }
                else 
                {
                    $explodedAgain = explode("&",$explodeArr[1]);
                    $embedId = $explodedAgain[0];
                }

             }
        ?>
    <div>
     <iframe width="300" height="160" src="http://www.youtube.com/embed/<?php echo $embedId ?>" frameborder="0" allowfullscreen></iframe>
    </div>
4
  • where this code i want to put @prasanta Hatui – Jaimin Feb 21 '17 at 6:44
  • $videourl is youtube video url and in phtml file you can put this. – Prasanta Hatui Feb 21 '17 at 6:46
  • default/template/catalog/product/view/media.phtml is it the file in which i want to put this code @prasanta Hatui – Jaimin Feb 21 '17 at 6:50
  • ok it's Working :) Thank you @prasanta Hatui – Jaimin Feb 21 '17 at 6:53

Not the answer you're looking for? Browse other questions tagged or ask your own question.