Skip to content

Commit 7abf7e2

Browse files
committed
优化Controller进度刷新
1 parent 78aabe8 commit 7abf7e2

6 files changed

Lines changed: 72 additions & 96 deletions

File tree

dkplayer-java/src/main/java/com/dueeeke/videoplayer/controller/BaseVideoController.java

Lines changed: 7 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ public boolean isLocked() {
264264
}
265265

266266
/**
267-
* 开始刷新进度
267+
* 开始刷新进度,注意:需在STATE_PLAYING时调用才会开始刷新进度
268268
*/
269269
@Override
270270
public void startProgress() {
@@ -283,33 +283,6 @@ public void stopProgress() {
283283
mIsStartProgress = false;
284284
}
285285

286-
@Override
287-
protected void onWindowVisibilityChanged(int visibility) {
288-
super.onWindowVisibilityChanged(visibility);
289-
if (mIsStartProgress) {
290-
if (visibility == VISIBLE) {
291-
post(mShowProgress);
292-
}
293-
}
294-
}
295-
296-
@Override
297-
protected void onAttachedToWindow() {
298-
super.onAttachedToWindow();
299-
if (mIsStartProgress) {
300-
post(mShowProgress);
301-
}
302-
checkCutout();
303-
}
304-
305-
@Override
306-
protected void onDetachedFromWindow() {
307-
super.onDetachedFromWindow();
308-
if (mIsStartProgress) {
309-
removeCallbacks(mShowProgress);
310-
}
311-
}
312-
313286
/**
314287
* 刷新进度Runnable
315288
*/
@@ -339,6 +312,12 @@ public void setAdaptCutout(boolean adaptCutout) {
339312
mAdaptCutout = adaptCutout;
340313
}
341314

315+
@Override
316+
protected void onAttachedToWindow() {
317+
super.onAttachedToWindow();
318+
checkCutout();
319+
}
320+
342321
/**
343322
* 检查是否需要适配刘海
344323
*/

dkplayer-sample/src/main/java/com/dueeeke/dkplayer/util/Utils.java

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import android.view.ViewParent;
55
import android.widget.FrameLayout;
66

7+
import com.dueeeke.videoplayer.player.VideoView;
78
import com.dueeeke.videoplayer.player.VideoViewConfig;
89
import com.dueeeke.videoplayer.player.VideoViewManager;
910

@@ -42,5 +43,63 @@ public static void removeViewFormParent(View v) {
4243
}
4344
}
4445

46+
/**
47+
* Returns a string containing player state debugging information.
48+
*/
49+
public static String playState2str(int state) {
50+
String playStateString;
51+
switch (state) {
52+
default:
53+
case VideoView.STATE_IDLE:
54+
playStateString = "idle";
55+
break;
56+
case VideoView.STATE_PREPARING:
57+
playStateString = "preparing";
58+
break;
59+
case VideoView.STATE_PREPARED:
60+
playStateString = "prepared";
61+
break;
62+
case VideoView.STATE_PLAYING:
63+
playStateString = "playing";
64+
break;
65+
case VideoView.STATE_PAUSED:
66+
playStateString = "pause";
67+
break;
68+
case VideoView.STATE_BUFFERING:
69+
playStateString = "buffering";
70+
break;
71+
case VideoView.STATE_BUFFERED:
72+
playStateString = "buffered";
73+
break;
74+
case VideoView.STATE_PLAYBACK_COMPLETED:
75+
playStateString = "playback completed";
76+
break;
77+
case VideoView.STATE_ERROR:
78+
playStateString = "error";
79+
break;
80+
}
81+
return String.format("playState: %s", playStateString);
82+
}
83+
84+
/**
85+
* Returns a string containing player state debugging information.
86+
*/
87+
public static String playerState2str(int state) {
88+
String playerStateString;
89+
switch (state) {
90+
default:
91+
case VideoView.PLAYER_NORMAL:
92+
playerStateString = "normal";
93+
break;
94+
case VideoView.PLAYER_FULL_SCREEN:
95+
playerStateString = "full screen";
96+
break;
97+
case VideoView.PLAYER_TINY_SCREEN:
98+
playerStateString = "tiny screen";
99+
break;
100+
}
101+
return String.format("playerState: %s", playerStateString);
102+
}
103+
45104

46105
}

dkplayer-sample/src/main/java/com/dueeeke/dkplayer/widget/component/DebugInfoView.java

Lines changed: 1 addition & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import com.dueeeke.videoplayer.exo.ExoMediaPlayerFactory;
2020
import com.dueeeke.videoplayer.ijk.IjkPlayerFactory;
2121
import com.dueeeke.videoplayer.player.AndroidMediaPlayerFactory;
22-
import com.dueeeke.videoplayer.player.VideoView;
2322
import com.dueeeke.videoplayer.thunder.ThunderMediaPlayerFactory;
2423

2524
/**
@@ -76,48 +75,10 @@ public void onPlayStateChanged(int playState) {
7675
* Returns the debugging information string to be shown by the target {@link TextView}.
7776
*/
7877
protected String getDebugString(int playState) {
79-
return getCurrentPlayer() + getPlayStateString(playState) + "\n"
78+
return getCurrentPlayer() + Utils.playState2str(playState) + "\n"
8079
+ "video width: " + mControlWrapper.getVideoSize()[0] + " , height: " + mControlWrapper.getVideoSize()[1];
8180
}
8281

83-
/**
84-
* Returns a string containing player state debugging information.
85-
*/
86-
protected String getPlayStateString(int state) {
87-
String playStateString;
88-
switch (state) {
89-
default:
90-
case VideoView.STATE_IDLE:
91-
playStateString = "idle";
92-
break;
93-
case VideoView.STATE_PREPARING:
94-
playStateString = "preparing";
95-
break;
96-
case VideoView.STATE_PREPARED:
97-
playStateString = "prepared";
98-
break;
99-
case VideoView.STATE_PLAYING:
100-
playStateString = "playing";
101-
break;
102-
case VideoView.STATE_PAUSED:
103-
playStateString = "pause";
104-
break;
105-
case VideoView.STATE_BUFFERING:
106-
playStateString = "buffering";
107-
break;
108-
case VideoView.STATE_BUFFERED:
109-
playStateString = "buffered";
110-
break;
111-
case VideoView.STATE_PLAYBACK_COMPLETED:
112-
playStateString = "playback completed";
113-
break;
114-
case VideoView.STATE_ERROR:
115-
playStateString = "error";
116-
break;
117-
}
118-
return String.format("playState: %s", playStateString);
119-
}
120-
12182
protected String getCurrentPlayer() {
12283
String player;
12384
Object playerFactory = Utils.getCurrentPlayerFactory();

dkplayer-sample/src/main/java/com/dueeeke/dkplayer/widget/component/PlayerMonitor.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import androidx.annotation.NonNull;
77

8+
import com.dueeeke.dkplayer.util.Utils;
89
import com.dueeeke.videoplayer.controller.ControlWrapper;
910
import com.dueeeke.videoplayer.controller.IControlComponent;
1011
import com.dueeeke.videoplayer.util.L;
@@ -30,12 +31,12 @@ public void onVisibilityChanged(boolean isVisible, Animation anim) {
3031

3132
@Override
3233
public void onPlayStateChanged(int playState) {
33-
L.d("onPlayStateChanged: " + playState);
34+
L.d("onPlayStateChanged: " + Utils.playState2str(playState));
3435
}
3536

3637
@Override
3738
public void onPlayerStateChanged(int playerState) {
38-
L.d("onPlayerStateChanged: " + playerState);
39+
L.d("onPlayerStateChanged: " + Utils.playerState2str(playerState));
3940
}
4041

4142
@Override

dkplayer-sample/src/main/java/com/dueeeke/dkplayer/widget/render/SurfaceRenderView.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package com.dueeeke.dkplayer.widget.render;
22

3-
import android.annotation.SuppressLint;
43
import android.content.Context;
54
import android.graphics.Bitmap;
65
import android.graphics.PixelFormat;
@@ -15,7 +14,6 @@
1514
import com.dueeeke.videoplayer.render.IRenderView;
1615
import com.dueeeke.videoplayer.render.MeasureHelper;
1716

18-
@SuppressLint("ViewConstructor")
1917
public class SurfaceRenderView extends SurfaceView implements IRenderView, SurfaceHolder.Callback {
2018
private MeasureHelper mMeasureHelper;
2119

dkplayer-ui/src/main/java/com/dueeeke/videocontroller/StandardVideoController.java

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import com.dueeeke.videocontroller.component.VodControlView;
2525
import com.dueeeke.videoplayer.controller.GestureVideoController;
2626
import com.dueeeke.videoplayer.player.VideoView;
27-
import com.dueeeke.videoplayer.util.L;
2827
import com.dueeeke.videoplayer.util.PlayerUtils;
2928

3029
/**
@@ -128,14 +127,12 @@ protected void onPlayerStateChanged(int playerState) {
128127
super.onPlayerStateChanged(playerState);
129128
switch (playerState) {
130129
case VideoView.PLAYER_NORMAL:
131-
L.e("PLAYER_NORMAL");
132130
setLayoutParams(new FrameLayout.LayoutParams(
133131
ViewGroup.LayoutParams.MATCH_PARENT,
134132
ViewGroup.LayoutParams.MATCH_PARENT));
135133
mLockButton.setVisibility(GONE);
136134
break;
137135
case VideoView.PLAYER_FULL_SCREEN:
138-
L.e("PLAYER_FULL_SCREEN");
139136
if (isShowing()) {
140137
mLockButton.setVisibility(VISIBLE);
141138
} else {
@@ -168,40 +165,21 @@ protected void onPlayStateChanged(int playState) {
168165
switch (playState) {
169166
//调用release方法会回到此状态
170167
case VideoView.STATE_IDLE:
171-
L.e("STATE_IDLE");
172168
mLockButton.setSelected(false);
173169
mLoadingProgress.setVisibility(GONE);
174170
break;
175171
case VideoView.STATE_PLAYING:
176-
L.e("STATE_PLAYING");
177-
mLoadingProgress.setVisibility(GONE);
178-
break;
179172
case VideoView.STATE_PAUSED:
180-
L.e("STATE_PAUSED");
181-
mLoadingProgress.setVisibility(GONE);
182-
break;
183-
case VideoView.STATE_PREPARING:
184-
L.e("STATE_PREPARING");
185-
mLoadingProgress.setVisibility(VISIBLE);
186-
break;
187173
case VideoView.STATE_PREPARED:
188-
L.e("STATE_PREPARED");
189-
mLoadingProgress.setVisibility(GONE);
190-
break;
191174
case VideoView.STATE_ERROR:
192-
L.e("STATE_ERROR");
175+
case VideoView.STATE_BUFFERED:
193176
mLoadingProgress.setVisibility(GONE);
194177
break;
178+
case VideoView.STATE_PREPARING:
195179
case VideoView.STATE_BUFFERING:
196-
L.e("STATE_BUFFERING");
197180
mLoadingProgress.setVisibility(VISIBLE);
198181
break;
199-
case VideoView.STATE_BUFFERED:
200-
L.e("STATE_BUFFERED");
201-
mLoadingProgress.setVisibility(GONE);
202-
break;
203182
case VideoView.STATE_PLAYBACK_COMPLETED:
204-
L.e("STATE_PLAYBACK_COMPLETED");
205183
mLoadingProgress.setVisibility(GONE);
206184
mLockButton.setVisibility(GONE);
207185
mLockButton.setSelected(false);

0 commit comments

Comments
 (0)