Skip to content

Commit

Permalink
规范化代码
Browse files Browse the repository at this point in the history
  • Loading branch information
Doikki committed Jul 18, 2022
1 parent b7f37c9 commit 536861a
Show file tree
Hide file tree
Showing 27 changed files with 86 additions and 96 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
*/
public class ControlWrapper implements MediaPlayerControl, IVideoController {

private MediaPlayerControl mPlayerControl;
private IVideoController mController;
private final MediaPlayerControl mPlayerControl;
private final IVideoController mController;

public ControlWrapper(@NonNull MediaPlayerControl playerControl, @NonNull IVideoController controller) {
mPlayerControl = playerControl;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ protected void slideToChangeBrightness(float deltaY) {
WindowManager.LayoutParams attributes = window.getAttributes();
int height = getMeasuredHeight();
if (mBrightness == -1.0f) mBrightness = 0.5f;
float brightness = deltaY * 2 / height * 1.0f + mBrightness;
float brightness = deltaY * 2 / height + mBrightness;
if (brightness < 0) {
brightness = 0f;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class AndroidMediaPlayer extends AbstractPlayer implements MediaPlayer.On

protected MediaPlayer mMediaPlayer;
private int mBufferedPercent;
private Context mAppContext;
protected Context mAppContext;
private boolean mIsPreparing;

public AndroidMediaPlayer(Context context) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
*/
final class AudioFocusHelper implements AudioManager.OnAudioFocusChangeListener {

private Handler mHandler = new Handler(Looper.getMainLooper());
private final Handler mHandler = new Handler(Looper.getMainLooper());

private WeakReference<BaseVideoView> mWeakVideoView;
private final WeakReference<BaseVideoView> mWeakVideoView;

private AudioManager mAudioManager;
private final AudioManager mAudioManager;

private boolean mStartRequested = false;
private boolean mPausedForLoss = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public class BaseVideoView<P extends AbstractPlayer> extends FrameLayout
/**
* {@link #mPlayerContainer}背景色,默认黑色
*/
private int mPlayerBackgroundColor;
private final int mPlayerBackgroundColor;

public BaseVideoView(@NonNull Context context) {
this(context, null);
Expand All @@ -144,11 +144,11 @@ public BaseVideoView(@NonNull Context context, @Nullable AttributeSet attrs, int
mRenderViewFactory = config.mRenderViewFactory;

//读取xml中的配置,并综合全局配置
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.VideoView);
mEnableAudioFocus = a.getBoolean(R.styleable.VideoView_enableAudioFocus, mEnableAudioFocus);
mIsLooping = a.getBoolean(R.styleable.VideoView_looping, false);
mCurrentScreenScaleType = a.getInt(R.styleable.VideoView_screenScaleType, mCurrentScreenScaleType);
mPlayerBackgroundColor = a.getColor(R.styleable.VideoView_playerBackgroundColor, Color.BLACK);
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.BaseVideoView);
mEnableAudioFocus = a.getBoolean(R.styleable.BaseVideoView_enableAudioFocus, mEnableAudioFocus);
mIsLooping = a.getBoolean(R.styleable.BaseVideoView_looping, false);
mCurrentScreenScaleType = a.getInt(R.styleable.BaseVideoView_screenScaleType, mCurrentScreenScaleType);
mPlayerBackgroundColor = a.getColor(R.styleable.BaseVideoView_playerBackgroundColor, Color.BLACK);
a.recycle();

initView();
Expand Down Expand Up @@ -728,9 +728,7 @@ public void startFullScreen() {

private void hideSysBar(ViewGroup decorView) {
int uiOptions = decorView.getSystemUiVisibility();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
uiOptions |= View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
}
uiOptions |= View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
uiOptions |= View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
}
Expand Down Expand Up @@ -775,9 +773,7 @@ public void stopFullScreen() {

private void showSysBar(ViewGroup decorView) {
int uiOptions = decorView.getSystemUiVisibility();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
uiOptions &= ~View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
}
uiOptions &= ~View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
uiOptions &= ~View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public Builder setEnableOrientation(boolean enableOrientation) {
}

/**
* 在移动环境下调用start()后是否继续播放,默认不继续播放
* 在移动环境下调用start()后是否继续播放,默认继续播放
*/
public Builder setPlayOnMobileNetwork(boolean playOnMobileNetwork) {
mPlayOnMobileNetwork = playOnMobileNetwork;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

import android.app.Application;

import xyz.doikki.videoplayer.util.L;

import java.util.LinkedHashMap;

import xyz.doikki.videoplayer.util.L;

/**
* 视频播放器管理器,管理当前正在播放的VideoView,以及播放器配置
* 你也可以用来保存常驻内存的VideoView,但是要注意通过Application Context创建,
Expand All @@ -16,7 +16,7 @@ public class VideoViewManager {
/**
* 保存VideoView的容器
*/
private LinkedHashMap<String, VideoView> mVideoViews = new LinkedHashMap<>();
private final LinkedHashMap<String, VideoView> mVideoViews = new LinkedHashMap<>();

/**
* 是否在移动网络下直接播放视频
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

@SuppressLint("ViewConstructor")
public class TextureRenderView extends TextureView implements IRenderView, TextureView.SurfaceTextureListener {
private MeasureHelper mMeasureHelper;
private final MeasureHelper mMeasureHelper;
private SurfaceTexture mSurfaceTexture;

@Nullable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ public static int getNetworkType(Context context) {
/**
* 通过反射获取Application
*
* @deprecated 不在使用,后期谷歌可能封掉改接口
* @deprecated 不在使用,后期谷歌可能封掉该接口
*/
@SuppressLint("PrivateApi")
@Deprecated
Expand Down
2 changes: 1 addition & 1 deletion dkplayer-java/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="VideoView">
<declare-styleable name="BaseVideoView">
<attr name="looping" format="boolean"/>
<attr name="enableAudioFocus" format="boolean"/>
<attr name="screenScaleType" format="dimension">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
public class PIPManager {

private static PIPManager instance;
private VideoView mVideoView;
private FloatView mFloatView;
private FloatController mFloatController;
private final VideoView mVideoView;
private final FloatView mFloatView;
private final FloatController mFloatController;
private boolean mIsShowing;
private int mPlayingPosition = -1;
private Class mActClass;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package xyz.doikki.dkplayer.util;

import androidx.collection.LruCache;
import android.text.TextUtils;

import androidx.collection.LruCache;

import xyz.doikki.videoplayer.player.ProgressManager;

public class ProgressManagerImpl extends ProgressManager {

//保存100条记录
private static LruCache<Integer, Long> mCache = new LruCache<>(100);
private static final LruCache<Integer, Long> mCache = new LruCache<>(100);

@Override
public void saveProgress(String url, long progress) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,19 @@ public class PreloadManager {
/**
* 单线程池,按照添加顺序依次执行{@link PreloadTask}
*/
private ExecutorService mExecutorService = Executors.newSingleThreadExecutor();
private final ExecutorService mExecutorService = Executors.newSingleThreadExecutor();

/**
* 保存正在预加载的{@link PreloadTask}
*/
private LinkedHashMap<String, PreloadTask> mPreloadTasks = new LinkedHashMap<>();
private final LinkedHashMap<String, PreloadTask> mPreloadTasks = new LinkedHashMap<>();

/**
* 标识是否需要预加载
*/
private boolean mIsStartPreload = true;

private HttpProxyCacheServer mHttpProxyCacheServer;
private final HttpProxyCacheServer mHttpProxyCacheServer;

/**
* 预加载的大小,每个视频预加载1M,这个参数可根据实际情况调整
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,25 @@
import androidx.annotation.Nullable;
import androidx.core.content.ContextCompat;

import xyz.doikki.dkplayer.R;
import xyz.doikki.videocontroller.component.VodControlView;
import xyz.doikki.videoplayer.player.VideoView;
import xyz.doikki.videoplayer.util.L;
import xyz.doikki.videoplayer.util.PlayerUtils;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.ListIterator;
import java.util.Map;

import xyz.doikki.dkplayer.R;
import xyz.doikki.videocontroller.component.VodControlView;
import xyz.doikki.videoplayer.player.VideoView;
import xyz.doikki.videoplayer.util.L;
import xyz.doikki.videoplayer.util.PlayerUtils;

public class DefinitionControlView extends VodControlView {

private TextView mDefinition;
private final TextView mDefinition;

private PopupWindow mPopupWindow;
private final PopupWindow mPopupWindow;
private List<String> mRateStr;
private LinearLayout mPopLayout;
private final LinearLayout mPopLayout;

private int mCurIndex;

Expand Down Expand Up @@ -125,7 +125,7 @@ public void setData(LinkedHashMap<String, String> multiRateData) {
}
}

private OnClickListener rateOnClickListener = new OnClickListener() {
private final OnClickListener rateOnClickListener = new OnClickListener() {

@Override
public void onClick(View v) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@

public class MyDanmakuView extends DanmakuView implements IControlComponent {

private DanmakuContext mContext;
private BaseDanmakuParser mParser;
private final DanmakuContext mContext;
private final BaseDanmakuParser mParser;

public MyDanmakuView(@NonNull Context context) {
super(context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ public class PipControlView extends FrameLayout implements IControlComponent, Vi

private ControlWrapper mControlWrapper;

private ImageView mPlay;
private ImageView mClose;
private ProgressBar mLoading;
private final ImageView mPlay;
private final ImageView mClose;
private final ProgressBar mLoading;

public PipControlView(@NonNull Context context) {
super(context);
Expand Down Expand Up @@ -82,19 +82,19 @@ public void onVisibilityChanged(boolean isVisible, Animation anim) {
if (mPlay.getVisibility() == VISIBLE)
return;
mPlay.setVisibility(VISIBLE);
mPlay.startAnimation(anim);
} else {
if (mPlay.getVisibility() == GONE)
return;
mPlay.setVisibility(GONE);
mPlay.startAnimation(anim);
}
mPlay.startAnimation(anim);
}

@Override
public void onPlayStateChanged(int playState) {
switch (playState) {
case VideoView.STATE_IDLE:
case VideoView.STATE_PAUSED:
mPlay.setSelected(false);
mPlay.setVisibility(VISIBLE);
mLoading.setVisibility(GONE);
Expand All @@ -104,12 +104,8 @@ public void onPlayStateChanged(int playState) {
mPlay.setVisibility(GONE);
mLoading.setVisibility(GONE);
break;
case VideoView.STATE_PAUSED:
mPlay.setSelected(false);
mPlay.setVisibility(VISIBLE);
mLoading.setVisibility(GONE);
break;
case VideoView.STATE_PREPARING:
case VideoView.STATE_BUFFERING:
mPlay.setVisibility(GONE);
mLoading.setVisibility(VISIBLE);
break;
Expand All @@ -122,10 +118,6 @@ public void onPlayStateChanged(int playState) {
mPlay.setVisibility(GONE);
bringToFront();
break;
case VideoView.STATE_BUFFERING:
mPlay.setVisibility(GONE);
mLoading.setVisibility(VISIBLE);
break;
case VideoView.STATE_BUFFERED:
mPlay.setVisibility(GONE);
mLoading.setVisibility(GONE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@

public class TikTokView extends FrameLayout implements IControlComponent {

private ImageView thumb;
private ImageView mPlayBtn;
private final ImageView thumb;
private final ImageView mPlayBtn;

private ControlWrapper mControlWrapper;
private int mScaledTouchSlop;
private final int mScaledTouchSlop;
private int mStartX, mStartY;

public TikTokView(@NonNull Context context) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import xyz.doikki.videoplayer.render.MeasureHelper;

public class SurfaceRenderView extends SurfaceView implements IRenderView, SurfaceHolder.Callback {
private MeasureHelper mMeasureHelper;
private final MeasureHelper mMeasureHelper;

private AbstractPlayer mMediaPlayer;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/
public class TikTokRenderView implements IRenderView {

private IRenderView mProxyRenderView;
private final IRenderView mProxyRenderView;

TikTokRenderView(@NonNull IRenderView renderView) {
this.mProxyRenderView = renderView;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class ExoVideoView extends BaseVideoView<CustomExoMediaPlayer> {
private RenderersFactory mRenderersFactory;
private TrackSelector mTrackSelector;

private ExoMediaSourceHelper mHelper;
private final ExoMediaSourceHelper mHelper;

public ExoVideoView(Context context) {
super(context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@

public class IjkVideoView extends BaseVideoView<CustomIjkMediaPlayer> {

private HashMap<String, Object> mPlayerOptions = new HashMap<>();
private HashMap<String, Object> mFormatOptions = new HashMap<>();
private HashMap<String, Object> mCodecOptions = new HashMap<>();
private HashMap<String, Object> mSwsOptions = new HashMap<>();
private final HashMap<String, Object> mPlayerOptions = new HashMap<>();
private final HashMap<String, Object> mFormatOptions = new HashMap<>();
private final HashMap<String, Object> mCodecOptions = new HashMap<>();
private final HashMap<String, Object> mSwsOptions = new HashMap<>();

public IjkVideoView(@NonNull Context context) {
super(context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class CompleteView extends FrameLayout implements IControlComponent {

private ControlWrapper mControlWrapper;

private ImageView mStopFullscreen;
private final ImageView mStopFullscreen;

public CompleteView(@NonNull Context context) {
super(context);
Expand Down
Loading

0 comments on commit 536861a

Please sign in to comment.