YouTube API Android auto start(YouTube API Android 自动启动)
问题描述
我在我的应用中使用 YouTube API.我的问题是,视频不会自动播放,用户必须按播放按钮才能开始播放.
I use YouTube API in my app. My problem is, the video does not auto play, and the user has to press the play button to start playing.
我的代码:
setContentView(R.layout.playerview_demo);
((YouTubePlayerView)findViewById(R.id.youtube_view)).initialize(DEV_KEY, this);
youtube_view
布局:
<com.google.android.youtube.player.YouTubePlayerView
android:id="@id/youtube_view"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
如何让视频自动开始播放?
How do I make the video start automatically?
推荐答案
你要找的是 Youtube API 的 loadVideo 方法.来自 文档:
What you are looking for is the Youtube API's loadVideo method. From the docs:
public abstract void loadVideo(String videoId)
加载并播放指定的视频.
Loads and plays the specified video.
你可以这样使用它:
@Override
public void onInitializationSuccess(YouTubePlayer.Provider provider, YouTubePlayer player,
boolean wasRestored) {
this.player = player;
player.loadVideo(video.id); // where video.id is a String of a Youtube video ID
}
类似地,还有 cueVideo
方法,它将视频添加到播放列表中,但不会自动开始播放视频.
In a similar vein, there is also the cueVideo
method, which adds the video to the playlist, but does not automatically start playing the video.
这篇关于YouTube API Android 自动启动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:YouTube API Android 自动启动


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