![Check out Enfold](https://kriesi.at/wp-content/themes/kriesi/images/banner-enfold.jpg)
-
AuthorPosts
-
September 24, 2020 at 9:24 pm #1248265
Hello again,
Me and a co-worker have put together some javascript that would allow video to play on our site when in the viewport and pause the video when you are outside of the viewport: https://codepen.io/trafficdaddy/pen/ExKrpPB
The problem is it appears the videos are being wrapped in mediaelementplayer which appears to be preventing our code to fire correctly.
example of one of our videos in the text block html:
<div id=”myVideo” data-aos=”fade-right” data-aos-duration=”1500″ data-aos-delay=”500″>[video muted="muted" width="800" mp4="http://maymobilitydev.wpengine.com/wp-content/uploads/2020/09/Masthead_Video_1920x1080.mp4" (hosted on WPengine) type="video/mp4"][/video]
</div>
our JS currently in the functions.php file:
function custom_video_scrolled_script(){
?>
<script>
(function ($) {
var media = $(‘video’).not(“[autoplay=’autoplay’]”);
//for media, you could give your scroll play videos a class if you need to make it more specific. This would play ALL html5 video tags when scrolled too.
var tolerancePixel = 80;$(document).on(‘scroll’, checkMedia);
function checkMedia(){
// Get current browser top and bottom
var scrollTop = $(window).scrollTop() + tolerancePixel;
var scrollBottom = $(window).scrollTop() + $(window).height() – tolerancePixel;media.each(function(index, el) {
var yTopMedia = $(this).offset().top;
var yBottomMedia = $(this).height() + yTopMedia;if(scrollTop < yBottomMedia && scrollBottom > yTopMedia){ //view explaination in
In brief
section above
$(this).get(0).play();
} else {
$(this).get(0).pause();
// $(this).get(0).currentTime = 0;
}
});
}
})(jQuery);
</script>
<?php
}
add_action(‘wp_head’, ‘custom_video_scrolled_script’);could you advise on the tweaks needed to make this work properly?
September 29, 2020 at 4:21 am #1249207Hey todd0218,
Thank you for the inquiry.
The script is no longer valid because of the new browsers’ autoplay policy. By default, the user or the site visitor has to play the media files manually.
This error occurs because the browser prevents the play function.
Uncaught (in promise) DOMException: The play method is not allowed by the user agent or the platform in the current context, possibly because the user denied permission.
Best regards,
IsmaelOctober 1, 2020 at 6:45 pm #1249915Hi Ismael I was able to use the JS code in conjunction with the core wordpress video functions, it seems the enfold player might be the culprit to make this work!
here is what i did:
<figure class=”wp-block-video”><video src=”video_url” autoplay=”autoplay” loop=”loop” muted=””></video></figure>October 5, 2020 at 12:32 pm #1250579Hi,
Thank you for the update.
In your previous example above, looks like you were already using the default video shortcode and not the theme’s, but we are glad to know that you managed to make it work using the default shortcode.
Does it work when you play the video on another network with a different IP address, or with a different device?
Best regards,
IsmaelOctober 14, 2020 at 9:33 pm #1252837yes it does!
October 16, 2020 at 3:49 pm #1253291Hi todd0218,
Glad you got it working for you! :)
If you need further assistance please let us know.
Best regards,
Victoria -
AuthorPosts
- You must be logged in to reply to this topic.