1

I tried to add in our androidx app the last Youtube Player for Publishers v2.1.2. To add this player we must create a new instance of YoutubeEmbedFragment extends Fragment.

The problem here is that this Fragment extends android.app.Fragment and in our application we use androidx.appcompat.app.AppCompatActivity and androidx.fragment.app so when I want to add this Youtube player fragment like :

getChildFragmentManager()
    .beginTransaction()
    .replace(R.id.player_container, youTubeEmbedFragment)
    .commit();

It won't compile because of

Wrong 2nd argument type. Found: 'com.google.android.youtube.player.YouTubeEmbedFragment', required: 'androidx.fragment.app.Fragment'

How can we stay using support fragment but also use the library ?

Linda Lawton - DaImTo
  • 106,405
  • 32
  • 180
  • 449
Emmanuel Loisance
  • 706
  • 1
  • 12
  • 22
  • 1
    Sharing link, in case you missed google result. try these solutions https://stackoverflow.com/q/52577000/3497972 – akashzincle Apr 13 '20 at 18:59
  • @akashzincle Yes I see this post, unfortunately it's a different version and the implementation has changed since. I have edit post to share version. – Emmanuel Loisance Apr 13 '20 at 20:13

1 Answers1

0

We are currently using AndroidX in our app and we had the same problem:

enter image description here

The Youtube Player for Publishers v2.1.2. is not using AndroidX so you have tu use "Fully Qualified name" to access the class android.app.FragmentTransaction and use the replace() method that requires android.app.Fragment from which youTubeEmbedFragment extends :

enter image description here

Jorgesys
  • 124,308
  • 23
  • 334
  • 268