Using the YouTube API within a fragment(在片段中使用 YouTube API)
问题描述
我在我的项目中使用了新的 YouTube API.使用文档的示例,它可以正常工作:
I using the new YouTube API in my project. Using the example of the documentation, it works correctly:
public class Test extends YouTubeBaseActivity implements YouTubePlayer.OnInitializedListener {
String urlVideo;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
urlVideo="5lbVNYAeFiQ";
YouTubePlayerView youTubeView = (YouTubePlayerView) findViewById(R.id.youtube_view);
youTubeView.initialize("MY_API_KEY", this);
}
public void onInitializationFailure(Provider arg0,YouTubeInitializationResult arg1) {
Toast.makeText(this, "Error ", Toast.LENGTH_LONG).show();
}
public void onInitializationSuccess(Provider arg0, YouTubePlayer arg1,boolean wasRestored) {
if (!wasRestored) {
arg1.loadVideo(urlVideo);
}
}
}
但在我的项目中,我正在使用一个包含 ViewPager 的主要活动ViewPager 显示片段,问题是当我想在 ViewPager 的一个片段中显示 YouTubePlayer 时.通常,一个使用 youtube 的活动,扩展 YouTubeBaseActivity.
But in my project, I'm using a main activity that contains a ViewPager The ViewPager shows fragments, the problem is when I want to show YouTubePlayer within one fragment of ViewPager. Normally, an activity that uses youtube, extending YouTubeBaseActivity.
extends YouTubeBaseActivity implements ... {
我的问题是,如何在从片段扩展的活动中显示 YouTube 播放器?
My question is, how I can show YouTube Player in an activity that extends from fragments?
我搜索过,但找不到有关我的问题的信息.
I searched, but can not find information about my problem.
衷心感谢您的帮助.
最好的问候
推荐答案
使用 YouTubePlayerSupportFragment 如果您只在单个 support.v4.app.Fragment 中播放 YouTube 视频.这允许您使用 FragmentActivity,而不是 YouTubeBaseActivity.
Use YouTubePlayerSupportFragment if you are only playing a YouTube video in a single support.v4.app.Fragment. This allows you to use FragmentActivity, rather than YouTubeBaseActivity.
这篇关于在片段中使用 YouTube API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在片段中使用 YouTube API


基础教程推荐
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01