Commit 69c52606 authored by jyx's avatar jyx

处理VideoView内存泄漏

parent 4637c22f
......@@ -10,7 +10,6 @@ import com.downloader.PRDownloader
import com.downloader.PRDownloaderConfig
import com.mints.goodmoney.manager.BxmManager.initBxm
import com.mob.MobSDK
import com.tencent.mm.opensdk.openapi.WXAPIFactory
/**
* 子线程初始化SDK
......
package com.mints.goodmoney.ui.activitys
import android.Manifest
import android.content.Context
import android.content.ContextWrapper
import android.media.MediaPlayer
import android.os.Bundle
import android.text.TextUtils
......@@ -469,4 +471,18 @@ class DrawNativeVideoActivity : BaseActivity(),
showToast("加载失败,请稍候再试")
finish()
}
override fun attachBaseContext(newBase: Context?) {
super.attachBaseContext(newBase)
// 处理VideoView setVideoPath方法中 AudioManager对Activity持有强引用,导致内存泄漏
object : ContextWrapper(newBase) {
override fun getSystemService(name: String): Any {
if (Context.AUDIO_SERVICE == name)
return applicationContext.getSystemService(name)
return super.getSystemService(name)
}
}
}
}
......@@ -8,10 +8,10 @@ import android.view.ViewGroup
import android.widget.*
import androidx.recyclerview.widget.RecyclerView
import com.mints.goodmoney.R
import com.mints.goodmoney.call.widget.CustomVideoView
import com.mints.goodmoney.mvp.model.DrawVideoBean
import com.mints.goodmoney.ui.activitys.DrawNativeVideoActivity
import com.mints.goodmoney.ui.adapter.listener.OnItemClickListener
import com.mints.goodmoney.ui.widgets.FullScreenVideoView
import com.mints.library.utils.GlideUtils
class DrawVideoAdapter(context: Context, datas: List<DrawVideoBean>) : RecyclerView.Adapter<RecyclerView.ViewHolder>() {
......@@ -62,7 +62,7 @@ class DrawVideoAdapter(context: Context, datas: List<DrawVideoBean>) : RecyclerV
}
private fun getView(): View {
val videoView = FullScreenVideoView(mContext)
val videoView = CustomVideoView(mContext)
val layoutParams = FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT)
videoView.layoutParams = layoutParams
return videoView
......
package com.mints.goodmoney.ui.widgets;
import android.content.Context;
import android.util.AttributeSet;
import android.widget.VideoView;
public class FullScreenVideoView extends VideoView {
public FullScreenVideoView(Context context) {
super(context);
}
public FullScreenVideoView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public FullScreenVideoView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int width = getDefaultSize(0, widthMeasureSpec);
int height = getDefaultSize(0, heightMeasureSpec);
setMeasuredDimension(width, height);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment