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

六眼飞鱼酱① 提交于 2019-12-20 01:42:10

问题


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 tried both of YoutubePlayerFragment and YoutubePlayerSupportFragment. Nothing works.
The logcat is like below:

W/YouTubeAndroidPlayerAPI: Cannot load modern controls UI. Upgrade to the latest version of the Android YouTube API.

I already updated the latest youtube api 1.2.2. But It's still not working.
The weird thing is that If I extend FragmentActivity or Activity, It works.
Please helps. Thanks in advance.


回答1:


For me the issue is that I am able to play the video only once but after that YouTubePlayer doesn't play any video and I hope there are many other people who are also facing similar issues with the YouTubeAndroidPlayerAPI. I think the latest youtube app (version 10.37.58) and YouTubeAndroidPlayerAPI 1.2.1 are not compatible.

To best of my knowledge the only thing you can do currently to solve this problem is downgrade your youtube app installed on the device to 10.36.52 or below. (you can get it from apk mirror)

From what I have noticed while working with YouTubeAndroidPlayerAPI is that with the youtube version 10.36.52 it throws warning messages "Cannot load modern controls UI. Upgrade to the latest version of the Android YouTube API." on the logcat everytime I try to play a video but otherwise works fine. And with version 10.35.53 and below no such warning message is thrown.

Reason: I am not sure but I think this has something to do with the huge memory leak issue with the YoutubePlayerSupport fragment in YouTubeAndroidPlayerAPI 1.2.1 which was widely known and reported in google data api issue tracker. It was finally fixed last month on 1st September (at least that's what the current status says) after a year since it was reported (surprised to see what took google so long). However google hasn't rolled out the new version of YouTubeAndroidPlayerAPI with the fix yet. So maybe they fixed that memory issue in the youtube app in September which some how broke the functionality of YouTubeAndroidPlayerAPI 1.2.1 in some way (since YouTubeAndroidPlayerAPI directly depends on the youtube app to work).




回答2:


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

<?xml version="1.0" encoding="utf-8" ?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingLeft="0dp"
android:paddingRight="0dp" android:paddingTop="0dp" android:paddingBottom="0dp" app:layout_behavior="@string/appbar_scrolling_view_behavior" tools:showIn="@layout/activity_you_tube_player" tools:context="com.stavira.ipaphonetics.YouTubePlayerActivity">

  <com.google.android.youtube.player.YouTubePlayerView android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/youtubePlayerView">
  </com.google.android.youtube.player.YouTubePlayerView>
</RelativeLayout>

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.


来源:https://stackoverflow.com/questions/33363456/cannot-load-modern-controls-ui-upgrade-to-the-latest-version-of-the-android-you

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!