After a lot of searching we have enabled autoplay with voice onscroll on our website but there is a problem

After searching a lot, we started autoplay with sound on our website but there is a problem that whenever the video comes inside the viewport, it starts automatically but when another video comes in the viewport, the above video should stop. Both videos play at the same time as long as both remain within the viewport.
This my code



$(window).scroll(function(e){

    if (!document.pictureInPictureElement) {

        $('.plyrr-<?php echo $wo['media']['storyId'].$rand ; ?>').each(function(){

            if ($(this).is(":in-viewport")) {

                jQuery(this).get(0).play();

            } else {

                $(this)[0].pause();

            }

        });

    }

});

It’s not working like instagram, facebook only one video play a time please set Viewport size if double video in viewport same time then one play second stop
Please check – https://pintrafeed.com/directory[enter image description here](https://i.sstatic.net/Uma6TDXE.jpg)