I use Youtube Api in my app, but my problem is it's not auto play, must press play button.
My code is:
setContentView(R.layout.playerview_demo);
((YouTubePlayerView)findViewById(R.id.youtube_view)).initialize(DEV_KEY, this);
youtube_view layout:
<com.google.android.youtube.player.YouTubePlayerView
android:id="@id/youtube_view"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
Using loadVideo function.
Loads and plays the specified video. Playback will start at the specified time in the video.
videoId - The ID of the video to be played timeMillis - The time in milliseconds
FYR: https://developers.google.com/youtube/android/player/reference/com/google/android/youtube/player/YouTubePlayer#loadVideo(java.lang.String)reader
Check that
autoplay
feature is set to1
. Player will load initial video inautoplay
by default.Please refer Youtube Autoplay parameters for more.
The documentation clearly states...
but u could simply call
youtubeplayer.loadVideo(VIDEO_ID,0) // 0 millis, start right away
Otherwise you could use CHROMELESS controls and add custom controls to it. Then it may work. All the best..
I have solve this myself, then i post here:
You need to use
player.cueVideo("video_id");
This will load the video, but it will not start auto playing. The video is auto playing because you're using
player.loadVideo("video_id");
.Hope it helps.
What you are looking for is the Youtube API's loadVideo method. From the docs:
You can use it like this:
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.