Hi guys. Is there a technique to enviornment background video to play handiest when it is contained in the viewport

Hi guys. Is there a technique to enviornment background video to play handiest when it is contained in the viewport