Incompatible fragment type with the Youtube Player for Publishers
Asked Answered
F

1

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 ?

Foundry answered 13/4, 2020 at 18:37 Comment(2)
Sharing link, in case you missed google result. try these solutions https://mcmap.net/q/528945/-youtube-player-support-fragment-no-longer-working-on-android-studio-3-2-androidx/3497972Zoubek
@Zoubek Yes I see this post, unfortunately it's a different version and the implementation has changed since. I have edit post to share version.Foundry
T
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

Thales answered 22/10, 2020 at 20:12 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.