Exoplayer在低端机型上未正常释放导致的ANR

1.背景

退出应用时会主动杀进程,在低端机型上退出应用时再次打开时会发生ANR,无法继续播放
堆栈如下:

  at java.lang.Object.wait!(Native method)
  - waiting on <0x1d8fed73> (a com.google.android.exoplayer2.ExoPlayerImplInternal)
  at com.google.android.exoplayer2.ExoPlayerImplInternal.waitUninterruptibly(ExoPlayerImplInternal.java:587)
  - locked <0x1d8fed73> (a com.google.android.exoplayer2.ExoPlayerImplInternal)
  at com.google.android.exoplayer2.ExoPlayerImplInternal.release(ExoPlayerImplInternal.java:402)
  - locked <0x1d8fed73> (a com.google.android.exoplayer2.ExoPlayerImplInternal)
  at com.google.android.exoplayer2.ExoPlayerImpl.release(ExoPlayerImpl.java:713)
  at com.google.android.exoplayer2.SimpleExoPlayer.release(SimpleExoPlayer.java:1710)
  at com.tcl.tliveplay.exoplayer.PlayerObject.release(PlayerObject.java:368)
  at com.tcl.tliveplay.pluginscn.MainController.release(MainController.java:317)

2.排查问题

通过trace可以看到,anr发生在waitUninterruptibly,通过源码发现是卡在wait方法中

  private synchronized void waitUninterruptibly(Supplier<Boolean> condition) {
    boolean wasInterrupted = false;
    while (!condition.get()) {
      try {
        wait();
      } catch (InterruptedException e) {
        wasInterrupted = true;
      }
    }
    if (wasInterrupted) {
      // Restore the interrupted status.
      Thread.currentThread().interrupt();
    }
  }

在exoplayer的githubissuue中发现有类似问题exoplayer 类似问题 issue
Exoplayer在低端机型上未正常释放导致的ANR_第1张图片
通过issue可以发现是没有调用播放器的release()就强制杀了进程,导致medecodec进入了错误的状态,导致该问题发生。

3.解决问题

找到原因解决问题就简单了,只要在对应杀进程前先调用播放器的release方法,该问题就会修复。此问题只会发生在一些低端机型上,大部分机型对medecodec的兼容都做得比较好,不会有该问题

你可能感兴趣的:(android,音视频)