Skip to content

2.1 Media Player Lifecycle

Nam Nguyen Hoai edited this page Oct 23, 2016 · 2 revisions

Video Player lifecycle

TL,DR: See ToroPlayer section and SimpleToroVideoViewHolder for more information.

ToroPlayer combines many basic Media Playback activities as well as the callback events from that. By that, it provides a good vision of what's going on while a Player is playing. Toro use that idea to create an abstract concept of Media Player lifecycle, which is visible from ToroPlayer core methods:

  /**
   * Host Activity becomes active.
   * Note that Activity behaviour is different from API 24+ to API 23-.
   */
  void onActivityActive();

  /**
   * Host Activity becomes inactive.
   * Note that Activity behaviour is different from API 24+ to API 23-.
   */
  void onActivityInactive();

  /* Playback lifecycle callback */

  /**
   * Preparing resources;
   */
  void onVideoPreparing();

  /**
   * Replace {@link android.media.MediaPlayer.OnPreparedListener#onPrepared(android.media.MediaPlayer)}
   */
  void onVideoPrepared();

  /**
   * Callback after this player starts playing
   */
  void onPlaybackStarted();

  /**
   * Callback after this player pauses playing
   */
  void onPlaybackPaused();

  /**
   * Callback after this player stops playing
   */
  void onPlaybackCompleted();

  boolean onPlaybackError(Exception error);

A long with this, Toro's PlayerViewHelper and MediaPlayerManager altogether will smartly access those method to provide best user experience. For example, user could setup a thumbnail in ToroPlayer#onVideoPrepared (or even in ToroAdapter$$ViewHolder#onViewHolderBound()), then animate that thumbnail to disappear right before playback starting in ToroPlayer#onPlaybackStarted() and so on. See VideoViewHolder for more information.

A ViewHolder that extends ToroAdapter$ViewHolder and implements ToroPlayer will give developer an overall UI lifecycle (ViewHolder's cycle and Player's cycle) which is easy to control and easy to provide best UX.

Clone this wiki locally