YouTube API Android自动启动 [英] YouTube API Android auto start

查看:71
本文介绍了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的

What you are looking for is the Youtube API's loadVideo method. From the docs:

公共抽象无效loadVideo(字符串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自动启动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆