Search in sources :

Example 1 with OnInitializedListener

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;
}
Also used : YouTubePlayer(com.google.android.youtube.player.YouTubePlayer) YouTubeInitializationResult(com.google.android.youtube.player.YouTubeInitializationResult) FragmentTransaction(android.support.v4.app.FragmentTransaction) OnInitializedListener(com.google.android.youtube.player.YouTubePlayer.OnInitializedListener) YouTubePlayerSupportFragment(com.google.android.youtube.player.YouTubePlayerSupportFragment) TextView(android.widget.TextView) View(android.view.View) Provider(com.google.android.youtube.player.YouTubePlayer.Provider)

Aggregations

FragmentTransaction (android.support.v4.app.FragmentTransaction)1 View (android.view.View)1 TextView (android.widget.TextView)1 YouTubeInitializationResult (com.google.android.youtube.player.YouTubeInitializationResult)1 YouTubePlayer (com.google.android.youtube.player.YouTubePlayer)1 OnInitializedListener (com.google.android.youtube.player.YouTubePlayer.OnInitializedListener)1 Provider (com.google.android.youtube.player.YouTubePlayer.Provider)1 YouTubePlayerSupportFragment (com.google.android.youtube.player.YouTubePlayerSupportFragment)1