我想实现youtube api,我注意到我必须具有从youTubeActivity类继承的活动。还有另一种没有youTubeactivity的播放YouTube视频的方法吗?如果有人喜欢我的例子,我想在recyclerview中运行它
答案 0 :(得分:1)
在您的回收站视图中使用YouTubePlayerView
答案 1 :(得分:0)
您可以使用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();
}