use of com.google.android.youtube.player.YouTubePlayer.OnInitializedListener in project Habba18 by chiragsastry1996.
the class YoutubeFragment method onCreateView.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_youtube, container, false);
backbutton = (Button) rootView.findViewById(R.id.back);
tName = (TextView) rootView.findViewById(R.id.name);
tCaption = (TextView) rootView.findViewById(R.id.caption);
VIDEO_ID = getArguments().getString("url");
Name = getArguments().getString("name");
Caption = getArguments().getString("caption");
tName.setText(Name);
tCaption.setText(Caption);
YouTubePlayerSupportFragment youTubePlayerFragment = YouTubePlayerSupportFragment.newInstance();
FragmentTransaction transaction = getChildFragmentManager().beginTransaction();
transaction.add(R.id.youtube_layout, youTubePlayerFragment).commit();
youTubePlayerFragment.initialize(API_KEY, new OnInitializedListener() {
@Override
public void onInitializationSuccess(Provider provider, YouTubePlayer player, boolean wasRestored) {
if (!wasRestored) {
player.setPlayerStyle(YouTubePlayer.PlayerStyle.DEFAULT);
player.loadVideo(VIDEO_ID);
player.play();
}
}
@Override
public void onInitializationFailure(Provider provider, YouTubeInitializationResult error) {
// YouTube error
String errorMessage = error.toString();
Log.d("errorMessage:", errorMessage);
}
});
backbutton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
getFragmentManager().popBackStack();
}
});
return rootView;
}
Aggregations