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 自动启动
基础教程推荐
- iPhone - 获取给定地点/时区的当前日期和时间并将其与同一地点的另一个日期/时间进行比较的正确方法 2022-01-01
- Android:getLastKnownLocation(LocationManager.NETWORK_PROVIDER 2022-01-01
- libGDX 从精灵或纹理中获取像素颜色 2022-01-01
- NSString intValue 不能用于检索电话号码 2022-01-01
- Cocos2d iPhone 非矩形精灵触摸检测 2022-01-01
- navigator.geolocation.getCurrentPosition 在 Android 浏览器上 2022-01-01
- 通过重定向链接在 Google Play 中打开应用 2022-01-01
- AdMob 广告未在模拟器中显示 2022-01-01
- iOS4 创建后台定时器 2022-01-01
- 如何从 logcat 中删除旧数据? 2022-01-01
