You need to enable JavaScript to run this app. 使用ExoPlayer的应用开启画中画后回退出现WindowLeaked泄漏与ANR如何解决
优惠活动
大模型
产品
解决方案
定价
更多

使用ExoPlayer的应用开启画中画后回退出现WindowLeaked泄漏与ANR如何解决

ExoPlayer 视频播放触发画中画模式的窗口泄漏与ANR问题

异常复现表现

  • 基于ExoPlayer实现的视频流播放功能,常规播放场景运行完全正常
  • 切换至画中画(PiP)模式后,系统自动将页面回退至返回栈中的上一个Activity,此时点击任意按钮会抛出窗口泄漏报错
  • 泄漏报错信息:WindowManager: android.view.WindowLeaked: Activity com.rcsrds.player.ui.main.MainActivity has leaked window DecorView@ff7d496[] that was originally added here
  • 异常仅在部分测试机型上复现,非全量设备可触发
  • 附带偶发异常:回退至上层Activity后的5秒窗口期内,多次点击任意按钮会偶发出现ANR问题

已完成的初步排查

  • 确认应用全链路未使用任何Dialog组件,排除Dialog未正常销毁引发的窗口泄漏
  • 应用内存在ProgressBar控件,但将相关代码全部注释后,窗口泄漏报错依然存在
  • 播放器为自定义View,怀疑该自定义实现与PiP流程的交互逻辑是问题触发原因

现有PiP实现代码

进入画中画模式的方法实现:

public void enterPictureInPicture(PictureInPictureParams nPipParams) {
    ActivityUtils.hideSystemUI(this.getWindow());
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        enterPictureInPictureMode(nPipParams);
    } else {
        //Toast.makeText(this,"Picture in Picture not availabe",Toast.LENGTH_LONG).show();
    }
}

MainActivity的清单配置:

<activity
    android:name=".ui.main.MainActivity"
    android:configChanges="screenSize|smallestScreenSize|screenLayout"
    android:supportsPictureInPicture="true"
    android:excludeFromRecents="true"
    android:autoRemoveFromRecents="true"
/>

内容的提问来源于stack exchange,提问作者BejanCorneliu

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.29 06:15:05