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.
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.
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 torequestFullScreen()
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 eventonplay
- you can't trigger
play()
via YouTube API (it would cross the frame) and callrequestFullScreen()
in the same tapSo with one tap either you play the video or get it fullscreen; you'll always need two separate taps if you use YouTube.
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.