TomMongo
TomMongo

Reputation: 21

Android Youtube API - is there an alternative for youtubeActivity

I want to implement youtube api, I noticed that I must have an activity inherited from the youTubeActivity class Is there another way to play YouTube video without having what youTubeactivity? I'd like to run it in a recyclerview if anyone has an example I'd love

Upvotes: 1

Views: 207

Answers (2)

Alex Ferents
Alex Ferents

Reputation: 298

youtube doc

Use YouTubePlayerView inside your recyclerview

Upvotes: 1

Ganesh Pokale
Ganesh Pokale

Reputation: 1594

You can use Youtube Fragment

    YouTubePlayerSupportFragment mYouTubePlayerSupportFragment = new YouTubePlayerSupportFragment();
                        mYouTubePlayerSupportFragment.initialize(beanAppConfig.getData().getYoutubeDetail().getDeveloperkey(),
                                new YouTubePlayer.OnInitializedListener() {
                                    @Override
                                    public void onInitializationSuccess(YouTubePlayer.Provider provider,
                                                                        YouTubePlayer youTubePlayer, boolean wasRestored) {

                                        myouTubePlayer = youTubePlayer;
                                        Log.e(TAG, "" + wasRestored);
                                        if (!wasRestored) {
                                            myouTubePlayer.loadVideo(youTubeVideoID);
                                            myouTubePlayer.setPlayerStateChangeListener(LiveActivityYoutube.this);
                                        }
                                    }

                                    @Override
                                    public void onInitializationFailure(YouTubePlayer.Provider provider,
                                                                        YouTubeInitializationResult youTubeInitializationResult) {
                                        Log.e("onInitializationFailure", "");
                                    }
                                });

                        mYouTubePlayerSupportFragment.setRetainInstance(true);

                       loadFragmentOverLay(mYouTubePlayerSupportFragment);

Load Fragment to FrameLayout

  private void loadFragmentOverLay(Fragment fragment) {
        // load fragment
        FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
        transaction.replace(frame_container_live.getId(), fragment);
        transaction.commit();
    }

Upvotes: 0

Related Questions