Giter Site home page Giter Site logo

Comments (1)

tonihei avatar tonihei commented on September 21, 2024 1

Thanks for the detailed problem description! As you already discovered, onEvents is the best choice to see all 'atomic' state updates in a single method. This method also gives you access to the Player to retrieve any current state values (in your example: the current media item, the playback state and playWhenReady). You are right that this doesn't allow to access additional event parameters like the reason for a playWhenReady change. If you need access to those, the best way is to overwrite the individual callback in addition to onEvents and just save the last parameter so you can use it from onEvents. As long as you check that the event happened, you are guaranteed that the value has been updated with the latest value and can be safely used. Please also see the last sentence in this guide that tries to highlight the same approach: https://developer.android.com/media/media3/exoplayer/listening-to-player-events#individual-callbacks

  int playWhenReadyChangeReason;

  public void onPlayWhenReadyChanged(boolean playWhenReady, int reason) {
   playWhenReadyChangeReason = reason;
  }

  public void onEvents(Player player, Events events) {
    if (events.contains(Player.EVENT_PLAY_WHEN_READY_CHANGED)
        && playWhenReadyChangeReason == Player.PLAY_WHEN_READY_CHANGE_REASON_USER_REQUEST 
        && player.getCurrentMediaItem() != null 
        && (player.getPlaybackState() == Player.STATE_BUFFERING 
            || player.getPlaybackState() == Player.STATE_READY)) {
      // ...
    }
  }

from media.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.