Exoplayer: Question: why player must be released in onPause for SDK<=23

Created on 27 Sep 2018  路  2Comments  路  Source: google/ExoPlayer

I see in the demo app that for sdk <=23 player is released in onPause
why it can't be done in onStop? what had changed for SDK > 23?

  public void onPause() {
    super.onPause();
    if (Util.SDK_INT <= 23) {
      releasePlayer();
    }
  }
question

All 2 comments

Player is released on pause to free up the resources as soon as possible but as of api 24, Android supports multi window so your app can be paused but still visible (and can continue playing video). That's why after api 23 player is released on stop.
https://developer.android.com/guide/topics/ui/multi-window

If I remember correctly, there were also some internal changes to the Android platform that provided stronger guarantees around onStop being called in a timely way, which were put in place from API 24. This made it feasible to release resources in onStop rather than onPause, without risk that whatever is replacing the activity in the foreground is then unable to acquire them.

Context: The stronger guarantees and the addition of multi-window support as @erdemguven describes were related. To support multi-window use cases where a media app is playing alongside some other foreground app, it's necessary for the media app to keep hold of resources up until onStop. This then required the stronger guarantees in the platform, to make sure such apps could still release resources in a timely way when they're fully hidden.

Was this page helpful?
0 / 5 - 0 ratings