YoutubeAndroidPlayerAPI error after migrating to AndroidX in Android Studio
Asked Answered
B

1

9

I have android native project (java) with YoutubeAndroidPlayerAPI.jar official library version 1.2.2 that have a function to be embedded Youtube Player in my App. Anything work fine before migrating to AndroidX.

I realized that the code inside the YoutubeAndroidPlayerAPI didn't support to AndroidX. The class of YoutubePlayerSupportFragment that extends to Fragment still use import android.support.v4.app.Fragment not androidx.fragment.app.Fragment.

i Can not edit the code of YoutubeAndroidPlayerAPI (read-only mode) for migrating to AndroidX.

This is my sample code of my project that getting error and red color warning at 'setArguments', 'getArguments' and 'getActivity'.

public class FragmentVideoPlayer extends YouTubePlayerSupportFragment implements YouTubePlayer.OnInitializedListener {

private YouTubePlayer player;
public FragmentVideoPlayer() {
    }

public static FragmentVideoPlayer newInstance(final String videoId) {
        final FragmentVideoPlayer youTubeFragment = new FragmentVideoPlayer();
        final Bundle bundle = new Bundle();
        bundle.putString(KEY_VIDEO_ID, videoId);
        youTubeFragment.setArguments(bundle);
        return youTubeFragment;
    }

    @Override
    public void onCreate(Bundle bundle) {
        super.onCreate(bundle);

        final Bundle arguments = getArguments();

        if (bundle != null && bundle.containsKey(KEY_VIDEO_ID)) {
            mVideoId = bundle.getString(KEY_VIDEO_ID);
        } else if (arguments != null && arguments.containsKey(KEY_VIDEO_ID)) {
            mVideoId = arguments.getString(KEY_VIDEO_ID);
        }

        String API_KEY = new SharedPref(getActivity()).getYoutubeApiKey();
        initialize(API_KEY, this);
    }
}

And this is some code from YoutubeAndroidPlayerAPI

    package com.google.android.youtube.player;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.google.android.youtube.player.YouTubePlayer.OnInitializedListener;
import com.google.android.youtube.player.YouTubePlayer.Provider;
import com.google.android.youtube.player.YouTubePlayerView.b;
import com.google.android.youtube.player.internal.ab;

public class YouTubePlayerSupportFragment extends Fragment implements Provider {
    private final YouTubePlayerSupportFragment.a a = new YouTubePlayerSupportFragment.a((byte)0);
    private Bundle b;
    private YouTubePlayerView c;
    private String d;
    private OnInitializedListener e;
    private boolean f;
}

Please, help me to solve this problem. How to fix YoutubeAndroidPlayerAPI jar file to supporting AndroidX?

Bunns answered 27/6, 2019 at 22:3 Comment(6)
Check this out: https://mcmap.net/q/1320932/-error-inflating-class-android-support-constraint-constraintlayoutTomikotomkiel
I already migrate via refactoring to AndroidX in Android Studio. And fix the problem manually one by one at some import such as fragment, etc. But, i have a problem to change the import code in fragment inside YoutubeAndroidPlayerAPI in Jar file that has read-only mode.Bunns
@Bunns have u found a solution to this?Sontag
Not yet. I just submit a bugs report to Google Team a couple days ago. And the progress is still in review. There are peoples that have same problem too.Bunns
I'm just starting a new personal project and I'm already facing this kind of issue..Saturated
@Bunns Did you figure it out? I'm having the same issue.Upturned
B
0

Youtube has not updated player library. You can use android-youtube-player https://github.com/PierfrancescoSoffritti/android-youtube-player It is very similar to native player. It uses webview and iframe to player video. It provides customizable player controlls.

Barri answered 9/6, 2020 at 11:17 Comment(1)
The last time they updated it was 6 years ago and I have a feeling that they won't be doing any more updates.Berkowitz

© 2022 - 2024 — McMap. All rights reserved.