Natalie
Natalie

Reputation: 1

Scroll To Play mode for JWPlayer

need an assistance to setup a Scroll To Play mode for JWPlayer. Anyone can help? Basically, I need a video to start only when a user scrolled down the page, where the video player is embed. Autoplay or Click To Play functions do not suit me here. Unfortunately, there is no built in functionality in the CMS of JWPlayer for Scroll To Play settings. Any advice on this will help me a lot! Thanks in advance!

Upvotes: 0

Views: 495

Answers (1)

luis
luis

Reputation: 1

You can start the player when the player is visible. Something like:

scrollView.getViewTreeObserver().addOnScrollChangedListener(
    new ViewTreeObserver.OnScrollChangedListener() {
        @Override
        public void onScrollChanged() {
            Rect scrollBounds = new Rect();
            scrollView.getHitRect(scrollBounds);
            if (player.getLocalVisibleRect(scrollBounds)) {
            // if player is visible (even a single pixel)
                if (player.getState() != PLAYING) {
                     player.play(true);
                }
            } else {
                // if player is not visible (even a single pixel)
                if (player.getState() == PLAYING) {
                    player.pause(true);
                }
            }
        }
    })

```

Upvotes: 0

Related Questions