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
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).
There is a quick work around for this problem as I applied to my app.
<?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) {
}
});
}
}