gpt4 book ai didi

java - MediaController/VideoView 导致 android.view.WindowLeaked

转载 作者:行者123 更新时间:2023-11-29 02:36:11 26 4
gpt4 key购买 nike

我有以下使用 VideoView 和 MediaController 的代码:

    FrameLayout frameLayout = findViewById(R.id.frameLayout);
VideoView videoView = findViewById(R.id.videoView);
mediaController = new MediaController(this) {
@Override
public void hide() {
// do not hide
}

public boolean dispatchKeyEvent(KeyEvent event) {
if (event.getKeyCode() == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_UP) {
((Activity) getContext()).finish();
}

return super.dispatchKeyEvent(event);
}
};
mediaController.setAnchorView(frameLayout);
videoView.setMediaController(mediaController);
videoView.setVideoPath("android.resource://" + getPackageName() + "/" + R.raw.meditation);

Handler handler = new Handler();
handler.postDelayed(new Runnable() {
public void run() {
mediaController.show(0);
}
}, 100);

问题是当 Activity 结束时,我在日志中收到以下错误:

10-28 05:57:16.075 6535-6535/com.kjdion.anxietynow E/WindowManager: android.view.WindowLeaked: Activity com.kjdion.anxietynow.MeditationActivity has leaked window DecorView@13fd277[] that was originally added here at android.view.ViewRootImpl.(ViewRootImpl.java:485) at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:346) at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:93) at android.widget.MediaController.show(MediaController.java:364) at com.kjdion.anxietynow.MeditationActivity$2.run(MeditationActivity.java:53) at android.os.Handler.handleCallback(Handler.java:790) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:164) at android.app.ActivityThread.main(ActivityThread.java:6494) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)

尽管出现此错误,但一切正常。

为什么会发生这种情况,我该如何解决?

最佳答案

这是因为您覆盖了 Controller 的隐藏方法,因此它不会隐藏。如果可以,请将其删除,代码应该可以正常工作。

关于java - MediaController/VideoView 导致 android.view.WindowLeaked,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46988476/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com