【问题标题】:Android Youtube API - is there an alternative for youtubeActivityAndroid Youtube API - 是否有 youtubeActivity 的替代方案
【发布时间】:2019-12-30 07:52:39
【问题描述】:

我想实现 youtube api,我注意到我必须有一个继承自 youTubeActivity 类的 Activity 是否有另一种方法可以在没有 youTubeactivity 的情况下播放 YouTube 视频?如果有人有我喜欢的例子,我想在回收站视图中运行它

【问题讨论】:

标签: android youtube-api


【解决方案1】:

youtube doc

在你的 recyclerview 中使用 YouTubePlayerView

【讨论】:

    【解决方案2】:

    您可以使用 Youtube 片段

        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);
    

    将片段加载到 FrameLayout

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

    【讨论】:

      猜你喜欢
      • 2020-11-28
      • 1970-01-01
      • 2014-01-29
      • 1970-01-01
      • 1970-01-01
      • 2020-10-07
      • 2012-09-02
      • 2016-08-06
      • 1970-01-01
      相关资源
      最近更新 更多