zeb*_*bhi 9 java android android-fragments android-youtube-api androidx
我有一个带有 YoutubeAndroidPlayerAPI.jar 官方库版本 1.2.2 的 android 原生项目(java),它具有在我的应用程序中嵌入 Youtube Player 的功能。在迁移到 AndroidX 之前一切正常。
我意识到 YoutubeAndroidPlayerAPI 中的代码不支持 AndroidX。扩展到 Fragment 的 YoutubePlayerSupportFragment 类仍然使用 import android.support.v4.app.Fragment 而不是 androidx.fragment.app.Fragment。
i 无法编辑用于迁移到 AndroidX 的 YoutubeAndroidPlayerAPI(只读模式)的代码。
这是我的项目的示例代码,在“setArguments”、“getArguments”和“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);
}
}
Run Code Online (Sandbox Code Playgroud)
这是来自 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;
}
Run Code Online (Sandbox Code Playgroud)
请帮我解决这个问题。如何修复 YoutubeAndroidPlayerAPI jar 文件以支持 AndroidX?
YouTube 尚未更新播放器库。您可以使用 android-youtube-player https://github.com/PierfrancescoSoffritti/android-youtube-player 它与本机播放器非常相似。它使用 webview 和 iframe 来播放视频。它提供可定制的播放器控件。