2017-09-22 65 views
0

//這是我的片段類 我需要顯示多個視頻在我的應用程序如何在我的活動中放置多個YouTube視頻請建議?

public class Testimonial extends Fragment { 

OnFragmentSelectedListener mCallback;

private YouTubePlayer YPlayer; 

private static final int RECOVERY_DIALOG_REQUEST = 1; 

// YouTube player view 
    @Nullable 
    @Override 

public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup 

container, @Nullable Bundle savedInstanceState) { 

//returning our layout file 
    //change R.layout.yourlayoutfilename for each of your fragments 

View view= inflater.inflate(R.layout.testimonial_fragment, container, 

false);

//我一直在使用框架佈局

YouTubePlayerSupportFragment youTubePlayerFragment = 

    YouTubePlayerSupportFragment.newInstance(); 



FragmentTransaction transaction = 

getChildFragmentManager().beginTransaction(); 

transaction.add(R.id.frame_fragment, youTubePlayerFragment).commit(); 


    youTubePlayerFragment.initialize("API_KEY", new 

YouTubePlayer.OnInitializedListener() { 

     @Override 
     public void onInitializationSuccess(YouTubePlayer.Provider arg0, 
    YouTubePlayer youTubePlayer, boolean wasRestored) { 
      if (!wasRestored) { 
       YPlayer = youTubePlayer; 
       // YPlayer.setFullscreen(false); 
       YPlayer.loadVideo("2zNSgSzhBfM"); 
       YPlayer.play(); 
       YPlayer.getFullscreenControlFlags(); 
      } 
     } 
@Override 

    return view; 
} 

} 

被用來YouTubePlayerSupportFragment類//我只能顯示一個視頻

回答

相關問題