I am trying to add a custom video to Fotorama slider at Product Page that I have uploaded at the storage of my server on this path: pub/media/videos
.
I have already tried this code, but didn’t work as I expected…
<script type="text/javascript">
require(['jquery'], function ($) {
$(document).on('gallery:loaded', function () {
var $fotorama = jQuery('div.gallery-placeholder > div.fotorama');
var fotorama = $fotorama.data('fotorama');
$fotorama.on('fotorama:load', function fotorama_onLoad(e, fotorama, extra) {
if (extra.frame.type === 'iframe') {
extra.frame.$stageFrame.html('<iframe align="middle" type="text/html" width="100%" height="100%" src="' + extra.frame.src + '" frameborder="0" scrolling="no" allowfullscreen webkitallowfullscreen mozallowfullscreen oallowfullscreen msallowfullscreen></iframe>');
}
});
fotorama.push({
thumb: 'pub/media/videos/product/video1.mp4',
'src': 'pub/media/videos/product/video1.mp4',
type: 'iframe',
caption: '<set your caption>'
});
});
});
</script>
2
Answers
I made a fork of fotorama files with an easy usage of HTML5 videos. Here is a functional example of how to use my update. This is only functional for MP4 videos. I modified Fotorama js for this situation that I also face before.
For more information, and README file, you can check it in GitHub.
Adding via JavaScript
Adding via module with PHP
File app/code/My/Module/etc/di.xml
File app/code/My/Module/Plugin/Gallery/Gallery.php