Skip to content

YouTubePlayer

Pierfrancesco Soffritti edited this page Jun 30, 2018 · 10 revisions

The documentation has been moved in the readme of the project. This wiki is outdated.


The YouTubePlayer is the component responsible for controlling the playback of YouTube videos. You can see its contract here.

You can only get a reference to the YouTubePlayer when initializing the YouTubePlayerView.

Events

During its existence the player will constantly emit events, you can easily listen to all of them by adding a YouTubePlayerListener to it (or an AbstractYouTubePlayerListener, if you don't want to implement all the methods of the YouTubePlayerListener interface).

Player state

The player has a state, that changes accordingly to the playback. The states in which the player can be are the same of the YouTube IFrame Player API.

UNKNOWN UNSTARTED ENDED PLAYING PAUSED BUFFERING VIDEO_CUED

YouTubePlayerTracker

YouTubePlayerTracker is an utility provided by the library to easily keep track of a YouTubePlayer's state.

YouTubePlayerTracker is a YouTubePlayerListener, in order to use it you need to add it as a listener to the YouTubePlayer

You can then use it to get the player's state and various information about the video that is being played.

YouTubePlayerTracker tracker = new YouTubePlayerTracker();
youtubePlayer.addListener(tracker);

tracker.getState();
tracker.getCurrentSecond();
tracker.getVideoDuration();
tracker.getVideoId();