Ashwin Prasad
Ashwin Prasad

Reputation: 79

YouTube Player View pausing video after each second

I understand that there are other similar questions asked. But they either have no solutions or the solutions provided are not working.

The player works fine in fullscreen mode but as a part of the layout contents, it keeps pausing and rebuffering.

Here is my code:

public class PlayerActivity extends YouTubeBaseActivity implements MediaPlayer.OnPreparedListener, YouTubePlayer.OnInitializedListener {
...
youTubePlayerView = (YouTubePlayerView) findViewById(R.id.player_youtube);
        Button yt_player_button = (Button) findViewById(R.id.player_yt_play);
        yt_player_button.setText("Click to play a Youtube video");
        yt_player_button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                youTubePlayerView.initialize(getString(R.string.youtube_api_key), PlayerActivity.this);
            }
        });
}
...
@Override
    public void onInitializationSuccess(YouTubePlayer.Provider provider, YouTubePlayer youTubePlayer, boolean b) {
        if (youTubePlayer ==  null)
            return;
        if (!b)
            youTubePlayer.cueVideo("63kmMcHBQlA");
    }

    @Override
    public void onInitializationFailure(YouTubePlayer.Provider provider, YouTubeInitializationResult youTubeInitializationResult) {

}

Upvotes: 1

Views: 709

Answers (1)

Ashwin Prasad
Ashwin Prasad

Reputation: 79

YoutubePlayerView cannot be nested inside a ScrollView for whatever the reason.

It just doesn't work. I suggest that you create a fragment which pops up during the request for the Youtube video or creating a new intent with just the YoutubePlayerView (maybe fullscreen). I couldn't find a reason as to why this is the case. (Please do add it as an answer if you know why) Using exo-player is a very good alternative too (If you can get the DASH Url's in a dynamic app. Then best of luck)

Upvotes: 1

Related Questions