我只是在我的一个Tab片段中使用YoutubePlayer,但无法集成它!
使用此代码,它会给我这个错误。
zip(my_list, my_list[1:], my_list[2:]))
这是我的片段类。
Binary XML file line #0: Error inflating class com.google.android.youtube.player.YouTubePlayerView
Caused by: android.view.InflateException: Binary XML file line #0: Error inflating class com.google.android.youtube.player.YouTubePlayerView
以下是我在public class Frag_Trailer extends Fragment {
YouTubePlayerView mYouTubePlayerView;
YouTubePlayer.OnInitializedListener mOnInitializatedListener;
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_trailer, container, false);
mYouTubePlayerView = (YouTubePlayerView)rootView.findViewById(R.id.view_youtube);
mYouTubePlayerView.initialize(YouTubeConfig.getYoutubeApiKey(), mOnInitializatedListener);
mOnInitializatedListener = new YouTubePlayer.OnInitializedListener() {
@Override
public void onInitializationSuccess(YouTubePlayer.Provider provider, YouTubePlayer youTubePlayer, boolean b) {
youTubePlayer.loadVideo("_XgQA9Ab0Gw");
}
@Override
public void onInitializationFailure(YouTubePlayer.Provider provider, YouTubeInitializationResult youTubeInitializationResult) {
}
};
return rootView;
}
}
中的依赖关系。
build.gradle
答案 0 :(得分:0)
基于此answer
您必须使用YouTubeBaseActivity
扩展您的活动。但是在你的情况下,你在Fragment上实现它,所以像这样改变你的视图XML
<fragment
android:name="com.google.android.youtube.player.YouTubePlayerSupportFragment"
android:id="@+id/youtubesupportfragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>