Android YouTubePlayerView 停止

Android YouTubePlayerView just stop

布局树

YouTubeBaseActivity
    └ ConstraintLayout
        └ ViewPager
           ├ LinearLayout
           │  └ SwipeRefreshLayout
           │     └ RecyclerView
           │        └ ConstraintLayout
           │           └ FrameLayout
           │              └ **YouTubePlayerView**
           │
           └ LinearLayout
               └ SwipeRefreshLayout
                   └ RecyclerView
                       └ ConstraintLayout
                           // There is only YTPlayerView on the first page

初始化

youTubeView.initialize(activity.getString(R.string.google_api_key), new YouTubePlayer.OnInitializedListener() {
    @Override
    public void onInitializationSuccess(YouTubePlayer.Provider provider, YouTubePlayer youTubePlayer, boolean b) {
        youTubePlayer.cueVideo("792WRHqbpE4");
    }

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

当我在1~2秒后按下PLAY键,它会自动暂停。

阅读 logcat 中的错误,您不能将任何视图与 YouTubePlayerView 重叠。

为了克服 YouTube 播放器的这些限制 API 我构建了一个开源 YouTube 播放器,它可能对您也有帮助。 android-youtube-player