Cannot load modern controls UI. Upgrade to the latest version of the Android YouTube API

前端 未结 2 1193
醉话见心
醉话见心 2021-01-21 03:38

I\'m trying to use Android Youtube API. Everything works ok excepts that when I extends AppCompatActivity. The UI of YoutubePlayer looks so bad. I trie

2条回答
  •  一整个雨季
    2021-01-21 03:52

    There is a quick work around for this problem as I applied to my app.

    1. First of all, you need to stop using YouTubePlayerFragment or YouTubePlayerSupportFragment
    2. Instead, create an activity contains YouTube video view. Here is my xml and Activity: activity_you_tube_player.xml

    
    
    
      
      
    

    Activity:

    public class YouTubePlayerActivity extends YouTubeBaseActivity {
    
    @Override
    protected void onCreate(final Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_you_tube_player);
    
        YouTubePlayerView playerView = (YouTubePlayerView) findViewById(R.id.youtubePlayerView);
    
        final String videoID = getIntent().getExtras().getString("videoID");
        playerView.initialize(YTConfig.DEVELOPER_KEY, new YouTubePlayer.OnInitializedListener() {
            @Override
            public void onInitializationSuccess(YouTubePlayer.Provider provider, YouTubePlayer youTubePlayer, boolean b) {
    
                youTubePlayer.setFullscreen(true);
                youTubePlayer.setShowFullscreenButton(true);
                youTubePlayer.setPlayerStyle(YouTubePlayer.PlayerStyle.MINIMAL);
                youTubePlayer.loadVideo(videoID.replace("https://www.youtube.com/watch?v=", ""));
    
                youTubePlayer.setPlayerStateChangeListener(new YouTubePlayer.PlayerStateChangeListener() {
                    @Override
                    public void onLoading() {
    
                    }
    
                    @Override
                    public void onLoaded(String s) {
    
                    }
    
                    @Override
                    public void onAdStarted() {
    
                    }
    
                    @Override
                    public void onVideoStarted() {
    
                    }
    
                    @Override
                    public void onVideoEnded() {
    
                    }
    
                    @Override
                    public void onError(YouTubePlayer.ErrorReason errorReason) {
    
                    }
                });
            }
    
            @Override
            public void onInitializationFailure(YouTubePlayer.Provider provider, YouTubeInitializationResult youTubeInitializationResult) {
    
            }
        });
    
    
    }
    

    }

    1. In the fragment where you previously host YouTube fragment, start the YouTube Activity with Intent.

提交回复
热议问题