2

I have a question in the Youtube API. I use the 'player.cueVideos' command to run the videos, but I wish that when a person hit the watch button they would be forced to full screen.

Thank you so much.

  • Possible duplicate of [play youtube video in full screen mode in my android app](http://stackoverflow.com/questions/11108441/play-youtube-video-in-full-screen-mode-in-my-android-app) – AL. Mar 09 '17 at 07:35

2 Answers2

0

I have run into a similar issue with forcing a iframe YouTube embed video full-screen on an Android. From the information that I've found it is impossible to force fullscreen on play on the Android with the YouTube API.

From a Codepen.io example by bfred-it:

Mobile browsers

This is the default behavior on iPhone, but it cannot work anywhere else (Android, iPad) since

  • to play() a video or to requestFullScreen() you need a user tap in the same document (read: not across the iframe)

This means that

  • you can't call requestFullScreen() when the video emits the event onplay
  • you can't trigger play() via YouTube API (it would cross the frame) and call requestFullScreen() in the same tap

So with one tap either you play the video or get it fullscreen; you'll always need two separate taps if you use YouTube.

Nathan Tuggy
  • 2,237
  • 27
  • 30
  • 38
ringside
  • 25
  • 5
0

Yes, you can:

public class YoutubeActivity extends YouTubeBaseActivity implements 
        YouTubePlayer.OnInitializedListener, 
        YouTubePlayer.PlayerStateChangeListener {

    private YouTubePlayer player;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.youtube_activity);

        YouTubePlayerView playerView = findViewById(R.id.youtube_player_view);
        playerView.initialize(YOUTUBE_API_KEY, this);
    }

    @Override
    public void onInitializationSuccess(YouTubePlayer.Provider provider, 
            YouTubePlayer youTubePlayer, boolean b) {
        //use this to hide controls
        youTubePlayer.setPlayerStyle(YouTubePlayer.PlayerStyle.CHROMELESS);
        player = youTubePlayer;
        youTubePlayer.setPlayerStateChangeListener(this);
        youTubePlayer.cueVideo(VIDEO_ID);
    }

    @Override
    public void onVideoStarted() {
        player.setFullscreen(true);
    }
}

Also, implement other methods that come with the interfaces.

YOUTUBE_API_KEY get your api key in here

VIDEO_ID You need to use the video's ID not full URL.

Documentation here.

hiddeneyes02
  • 2,562
  • 1
  • 31
  • 58