Background Video only play the first on IOS Mobile

Hi I applied the following JS in my custom code, and the background video will only play the first video on IOS. I am new to JS and I am wondering how to make videos to play when in the viewport on scroll? Thanks a lot!

var mobilevideo = document.getElementsByTagName(“video”)[0];
mobilevideo.setAttribute(“playsinline”, “”);