Search code examples
javaandroidyoutubeandroid-youtube-api

Youtube player stops when scrolling down


I have seen other questions like this and this but they didn't solve my problem. I know how to configure player not to stop when screen rotates and so on, but in my activity I have a youtube player at the beginning of the activity and below it a scrollable content now when the user scrolls down and the player is not shown in the screen I need it to continue playing, in my case it is pausing, and I want the youtube player to scroll up it is not an option to make the youtube player fixed since below it there is a big form that needs to be filled so I want the form to scroll up above the youtube player. So my question how to prevent youtube player from stopping when scrolling down int the activity?? These are my implementations of youtube player:

 youTubeView = (YouTubePlayerView) findViewById(R.id.youtube_view);
    youTubeView.initialize(Config.DEVELOPER_KEY, this);

   @Override
public void onInitializationFailure(YouTubePlayer.Provider provider,
                                    YouTubeInitializationResult errorReason) {
    if (errorReason.isUserRecoverableError()) {
        errorReason.getErrorDialog(this, RECOVERY_DIALOG_REQUEST).show();
    } else {
        String errorMessage = "error";
        Toast.makeText(this, errorMessage, Toast.LENGTH_LONG).show();
    }
}

@Override
public void onInitializationSuccess(YouTubePlayer.Provider provider,
                                    YouTubePlayer player, boolean wasRestored) {
    if (!wasRestored) {

        // loadVideo() will auto play video
        // Use cueVideo() method, if you don't want to play it automatically
        player.cueVideo("3HI2di53DMI");


        // Hiding player controls
        player.setPlayerStyle(YouTubePlayer.PlayerStyle.DEFAULT);

    }
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == RECOVERY_DIALOG_REQUEST) {
        // Retry initialization if user performed a recovery action
        getYouTubePlayerProvider().initialize(Config.DEVELOPER_KEY, this);
    }
}

private YouTubePlayer.Provider getYouTubePlayerProvider() {
    return (YouTubePlayerView) findViewById(R.id.youtube_view);
}

Solution

  • This actually can't be done without the whole video being shown, as you can see the android Youtube app by Google, they made the video stick to the top, and the content is scrolling under it, if you enlarge the player, it covers the whole page, so actually for the meanwhile even Google can't do so...