Youtube Api android autostart

后端 未结 6 1456
梦谈多话
梦谈多话 2020-12-01 10:56

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);
((Y         


        
相关标签:
6条回答
  • 2020-12-01 11:14

    Check that autoplay feature is set to 1. Player will load initial video in autoplay by default.

    Please refer Youtube Autoplay parameters for more.

    0 讨论(0)
  • 2020-12-01 11:18

    Using loadVideo function.

    public abstract void loadVideo (String videoId, int timeMillis)
    

    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

    0 讨论(0)
  • 2020-12-01 11:18

    I have solve this myself, then i post here:

     public void onInitializationSuccess(YouTubePlayer.Provider paramProvider, YouTubePlayer  paramYouTubePlayer, boolean paramBoolean)
     {if (!paramBoolean)paramYouTubePlayer.loadVideo(CLIP_LINK);}
    
    0 讨论(0)
  • 2020-12-01 11:18

    The documentation clearly states...

    Note: YouTube only counts playbacks that are initiated through the native play button.

    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..

    0 讨论(0)
  • 2020-12-01 11:20

    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.

    You can use it like this:

    @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
    }
    

    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.

    0 讨论(0)
  • 2020-12-01 11:23

    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.

    0 讨论(0)
提交回复
热议问题