我正在一个应用程序中展示视频,以下是在 VideoActivity
中使用的代码:
binding.videoView.setVideoURI(videoUri);
binding.videoView.requestFocus();
binding.videoView.start();
binding.videoView.setOnPreparedListener(new
MediaPlayer.OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mediaPlayer) {
binding.progressBar.progressOverlay.setVisibility(View.GONE);
}
});
binding.videoView.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mediaPlayer) {
binding.videoView.suspend();
binding.videoView.stopPlayback();
setResult(RESULT_OK);
finish();
}
});
binding.videoSkipButton.setOnClickListener(
new View.OnClickListener() {
@Override
public void onClick(View view) {
binding.videoView.suspend();
binding.videoView.stopPlayback();
setResult(RESULT_OK);
finish();
}
});
跳过/结束后,我收到了一个来自LeakCanary的报告,显示我的活动存在泄漏:
![enter image description here](https://istack.dev59.com/DDDPh.webp)
我也看到了类似的LeakCanary跟踪问题:VideoView memory leak 但是那里的问题出在ButterKnife解绑上。我需要对DataBinding做类似的操作吗?