在viewpager标签

时间:2017-02-04 03:16:47

标签: android android-viewpager android-recyclerview android-tabs android-youtube-api

我在recyclerview中实现了YouTubePlayerSupportFragment(),但是当我从另一个标签切换到YouTube视频标签时,它只加载第一个视频和屏幕闪烁。

@Override
public void onBindViewHolder(VideoHolder holder, final int position) {
holder.name.setText(videoList.get(position).getVideoContent());
videoId=videoList.get(position).getSharedVideosId();
mYoutubePlayerFragment = new YouTubePlayerSupportFragment();
mYoutubePlayerFragment.initialize(API_KEY, this);
FragmentManager fragmentManager       =((Classroom)context).getSupportFragmentManager();
    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
    fragmentTransaction.replace(R.id.youtube_fragment_container, mYoutubePlayerFragment);
    fragmentTransaction.commit();
}
@Override
public void onInitializationSuccess(YouTubePlayer.Provider provider,   YouTubePlayer player, boolean wasRestored) {
    if(!wasRestored){
    player.cueVideo(videoId);
}}
@Override
public void onInitializationFailure(YouTubePlayer.Provider provider,
                                    YouTubeInitializationResult result) {
    if (result.isUserRecoverableError()) {
        result.getErrorDialog((Classroom) context,1).show();
    } else {
        Toast.makeText(context,
                "YouTubePlayer.onInitializationFailure(): " +    result.toString(),
                Toast.LENGTH_LONG).show();}
}

这是我的framelayout,我正在加载youtube视频

<FrameLayout
    android:id="@+id/youtube_fragment_container"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"/>

0 个答案:

没有答案