Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use Youtube Player with modern UI in Android using YoutubePlayerSupportFragment

I am trying to use Youtube Player in my android app. It is showing a old outdated UI for the player but in the samples its showing a modern UI. The only difference between the two apps is I am using YoutubePlayerSupportFragment instead of YoutubePlayerFragment. This is because i am using AppCompatActivity for Material Theme in pre lollipop devices.

I am getting the below statement in logs:

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

How to overcome this problem ? I need the modern UI using Appcompat and YoutubePlayerSupportFragment

like image 646
Kalyan Avatar asked Oct 04 '15 14:10

Kalyan


2 Answers

I found something that worked for me.

Set this before super.OnCreate() in the Activity your fragment is currently on:

getLayoutInflater().setFactory(this);

like image 125
Arnold Balliu Avatar answered Nov 14 '22 09:11

Arnold Balliu


My guess is that the YouTube APIs have yet to be updated.

Consider this:

  • the YouTube Android Player API (found here) is just a bunch of remote Views that link to the official YouTube application, that needs to be installed on the device for it to work
  • the YouTube app is now minSdk 15, meaning that Fragments are natively supported
  • as you mentioned, everything works with YouTubePlayerFragment, but not with YouTubePlayerSupportFragment

I believe that the YouTube 'SDK' can directly import the player view from the YouTube app, taking advantage of the modern UI controls. However, support Fragments require more actions on the SDK side, actions which are yet to be taken in the form of an update.

TL;DR

Your best bet is waiting for the YouTube APIs to be updated to a newer version.


EDIT

Looks like the YouTube SDK has just been updated to 1.2.2! Head over here to download it.

like image 23
Sebastiano Avatar answered Nov 14 '22 08:11

Sebastiano