YouTube播放器观看缓冲的视频丢失

时间:2018-11-21 11:02:52

标签: android youtube youtube-api android-youtube-api

在方向更改时,缓冲的视频流丢失,并且播放器重新加载视频然后播放。如何避免缓冲流的丢失。我已经按照以下方式初始化了播放器。

@Override
public void onInitializationSuccess(YouTubePlayer.Provider provider, YouTubePlayer youTubePlayer, boolean wasRestored)
{

    // Checking whether video is restored or not
    if (!wasRestored)
    {
        // If not restored load video
        // Defining player
        player = youTubePlayer;

        // Setting flag for the player to play video in fullscreen mode when switched to landscaper orientation
        player.setFullscreenControlFlags(YouTubePlayer.FULLSCREEN_FLAG_CONTROL_ORIENTATION | YouTubePlayer.FULLSCREEN_FLAG_ALWAYS_FULLSCREEN_IN_LANDSCAPE);

        // Attaching onFullScreenListener to player
        player.setOnFullscreenListener(new YouTubePlayer.OnFullscreenListener()
        {
            @Override
            public void onFullscreen(boolean isFullScreen)
            {
                // onFullScreen setting flag to true
                playingInFullscreen = isFullScreen;
            }
        });


        player.setPlayerStyle(YouTubePlayer.PlayerStyle.DEFAULT);
        player.loadVideo(videoId);
    }
    else
    {
        Log.i("VideoPlayer", "was restored");
    }

}

1 个答案:

答案 0 :(得分:0)

作为一种方法,当方向改变时,您可以禁止重新创建玩家活动。在YouTube播放器所在的活动清单中

android:configChanges="screenSize|orientation"