public VideoPlayerIJK(@NonNull Context context, @Nullable AttributeSet attrs, @AttrRes int defStyleAttr) {
super(context, attrs, defStyleAttr);
initVideoView(context);
}
private void initVideoView(Context context) {
mContext = context;
//获取焦点,不知道有没有必要。
setFocusable(true);
}
/**
-
设置视频地址。
-
根据是否第一次播放视频,做不同的操作。
-
@param path the path of the video.
*/
public void setVideoPath(String path) {
if (TextUtils.equals(“”, mPath)) {
//如果是第一次播放视频,那就创建一个新的surfaceView
mPath = path;
createSurfaceView();
} else {
//否则就直接load
mPath = path;
load();
}
}
/**
- 新建一个surfaceview
*/
private void createSurfaceView() {
//生成一个新的surface view
surfaceView = new SurfaceView(mContext);
surfaceView.getHolder().addCallback(new LmnSurfaceCallback());
LayoutParams layoutParams = new LayoutParams(LayoutParams.MATCH_PARENT
, LayoutParams.MATCH_PARENT, Gravity.CENTER);
surfaceView.setLayoutParams(layoutParams);
this.addView(surfaceView);
}
/**
- surfaceView的监听器
*/
private clas