Search in sources :

Example 1 with YouTubeInitializationResult

use of com.google.android.youtube.player.YouTubeInitializationResult in project DraggablePanel by pedrovgs.

the class YoutubeSampleActivity method initializeYoutubeFragment.

/**
   * Initialize the YouTubeSupportFrament attached as top fragment to the DraggablePanel widget and
   * reproduce the YouTube video represented with a YouTube url.
   */
private void initializeYoutubeFragment() {
    youtubeFragment = new YouTubePlayerSupportFragment();
    youtubeFragment.initialize(YOUTUBE_API_KEY, new YouTubePlayer.OnInitializedListener() {

        @Override
        public void onInitializationSuccess(YouTubePlayer.Provider provider, YouTubePlayer player, boolean wasRestored) {
            if (!wasRestored) {
                youtubePlayer = player;
                youtubePlayer.loadVideo(VIDEO_KEY);
                youtubePlayer.setShowFullscreenButton(true);
            }
        }

        @Override
        public void onInitializationFailure(YouTubePlayer.Provider provider, YouTubeInitializationResult error) {
        }
    });
}
Also used : YouTubePlayer(com.google.android.youtube.player.YouTubePlayer) YouTubeInitializationResult(com.google.android.youtube.player.YouTubeInitializationResult) YouTubePlayerSupportFragment(com.google.android.youtube.player.YouTubePlayerSupportFragment)

Example 2 with YouTubeInitializationResult

use of com.google.android.youtube.player.YouTubeInitializationResult 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)

Example 3 with YouTubeInitializationResult

use of com.google.android.youtube.player.YouTubeInitializationResult in project Reader by TheKeeperOfPie.

the class FragmentComments method loadYoutubeVideo.

private void loadYoutubeVideo(final String id, final int timeInMillis) {
    if (youTubePlayer != null) {
        toggleYouTubeVisibility(View.VISIBLE);
        if (!id.equals(currentYouTubeId)) {
            youTubePlayer.loadVideo(id);
            currentYouTubeId = id;
        }
        return;
    }
    youTubeFragment = new YouTubePlayerSupportFragment();
    layoutYouTube.setId(youTubeViewId);
    getFragmentManager().beginTransaction().add(youTubeViewId, youTubeFragment, String.valueOf(youTubeViewId)).commit();
    youTubeFragment.initialize(ApiKeys.YOUTUBE_API_KEY, new YouTubePlayer.OnInitializedListener() {

        @Override
        public void onInitializationSuccess(YouTubePlayer.Provider provider, YouTubePlayer player, boolean b) {
            FragmentComments.this.youTubePlayer = player;
            youTubePlayer.setManageAudioFocus(false);
            youTubePlayer.setFullscreenControlFlags(YouTubePlayer.FULLSCREEN_FLAG_CONTROL_SYSTEM_UI);
            DisplayMetrics displayMetrics = getActivity().getResources().getDisplayMetrics();
            boolean isLandscape = displayMetrics.widthPixels > displayMetrics.heightPixels;
            if (isLandscape) {
                youTubePlayer.setOnFullscreenListener(new YouTubePlayer.OnFullscreenListener() {

                    @Override
                    public void onFullscreen(boolean fullscreen) {
                        isFullscreen = fullscreen;
                        if (!fullscreen) {
                            releaseYouTube();
                            toggleYouTubeVisibility(View.GONE);
                        }
                    }
                });
            } else {
                youTubePlayer.setOnFullscreenListener(new YouTubePlayer.OnFullscreenListener() {

                    @Override
                    public void onFullscreen(boolean fullscreen) {
                        isFullscreen = fullscreen;
                    }
                });
            }
            youTubePlayer.setPlayerStateChangeListener(new YouTubePlayerStateListener(youTubePlayer, timeInMillis, isLandscape));
            toggleYouTubeVisibility(View.VISIBLE);
            youTubePlayer.loadVideo(id);
            currentYouTubeId = id;
        }

        @Override
        public void onInitializationFailure(YouTubePlayer.Provider provider, YouTubeInitializationResult youTubeInitializationResult) {
        }
    });
}
Also used : YouTubePlayer(com.google.android.youtube.player.YouTubePlayer) YouTubeInitializationResult(com.google.android.youtube.player.YouTubeInitializationResult) YouTubePlayerSupportFragment(com.google.android.youtube.player.YouTubePlayerSupportFragment) DisplayMetrics(android.util.DisplayMetrics) YouTubePlayerStateListener(com.winsonchiu.reader.utils.YouTubePlayerStateListener)

Example 4 with YouTubeInitializationResult

use of com.google.android.youtube.player.YouTubeInitializationResult in project EdenYouTube by Glurt.

the class MainActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    // Only add the toolbar if we are on Honeycomb and above
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
    }
    // Check for any issues
    final YouTubeInitializationResult result = YouTubeApiServiceUtil.isYouTubeApiServiceAvailable(this);
    if (result != YouTubeInitializationResult.SUCCESS) {
        // If there are any issues we can show an error dialog.
        result.getErrorDialog(this, 0).show();
    }
}
Also used : YouTubeInitializationResult(com.google.android.youtube.player.YouTubeInitializationResult) Toolbar(android.support.v7.widget.Toolbar)

Aggregations

YouTubeInitializationResult (com.google.android.youtube.player.YouTubeInitializationResult)4 YouTubePlayer (com.google.android.youtube.player.YouTubePlayer)3 YouTubePlayerSupportFragment (com.google.android.youtube.player.YouTubePlayerSupportFragment)3 FragmentTransaction (android.support.v4.app.FragmentTransaction)1 Toolbar (android.support.v7.widget.Toolbar)1 DisplayMetrics (android.util.DisplayMetrics)1 View (android.view.View)1 TextView (android.widget.TextView)1 OnInitializedListener (com.google.android.youtube.player.YouTubePlayer.OnInitializedListener)1 Provider (com.google.android.youtube.player.YouTubePlayer.Provider)1 YouTubePlayerStateListener (com.winsonchiu.reader.utils.YouTubePlayerStateListener)1