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 自动启动
基础教程推荐
- navigationItem.backBarButtonItem 不工作?为什么上一个菜单仍然显示为按钮? 2022-01-01
- iOS - UINavigationController 添加多个正确的项目? 2022-01-01
- UIImage 在开始时不适合 UIScrollView 2022-01-01
- Play 商店的设备兼容性问题 2022-01-01
- Android Volley - 如何动画图像加载? 2022-01-01
- 如何比较两个 NSDate:哪个是最近的? 2022-01-01
- SwiftUI-ScrollViewReader的ScrollTo不滚动 2022-01-01
- 如何将图像从一项活动发送到另一项活动? 2022-01-01
- 为什么姜饼模拟器方向卡在应用程序中? 2022-01-01
- Xcode UIView.init(frame:) 只能在主线程中使用 2022-01-01
