Skip to content

Commit 66f0fb9

Browse files
author
Ttt
committed
1.增加自动播放处理
Former-commit-id: d42ffc4
1 parent 073081c commit 66f0fb9

File tree

1 file changed

+34
-5
lines changed

1 file changed

+34
-5
lines changed

DevLibUtils/src/main/java/dev/utils/app/player/DevVideoPlayerControl.java

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,25 @@ public class DevVideoPlayerControl implements SurfaceHolder.Callback,
2424
private SurfaceView mSurfaceview;
2525
/** 画面预览回调 */
2626
private SurfaceHolder mSurfaceHolder;
27+
/** 判断是否自动播放 */
28+
private boolean isAutoPlay = false;
2729

2830
/**
2931
* 初始化构造函数
3032
* @param surfaceview
3133
*/
3234
public DevVideoPlayerControl(SurfaceView surfaceview) {
35+
this(surfaceview, false);
36+
}
37+
38+
/**
39+
* 初始化构造函数
40+
* @param surfaceview
41+
* @param isAutoPlay
42+
*/
43+
public DevVideoPlayerControl(SurfaceView surfaceview, boolean isAutoPlay) {
3344
this.mSurfaceview = surfaceview;
45+
this.isAutoPlay = isAutoPlay;
3446

3547
// = 初始化操作 =
3648

@@ -100,17 +112,18 @@ public void onPrepared() {
100112
} catch (Exception e) {
101113
LogPrintUtils.eTag(TAG, e, "onPrepared");
102114
}
103-
104-
// 触发回调
105-
if (mMediaListener != null){
106-
mMediaListener.onPrepared();
107-
} else {
115+
// 判断是否自动播放
116+
if (isAutoPlay){
108117
try { // 如果没有设置则直接播放
109118
DevMediaManager.getInstance().getMediaPlayer().start();
110119
} catch (Exception e){
111120
LogPrintUtils.eTag(TAG, e, "onPrepared - start");
112121
}
113122
}
123+
// 触发回调
124+
if (mMediaListener != null){
125+
mMediaListener.onPrepared();
126+
}
114127
}
115128
}
116129

@@ -265,6 +278,22 @@ public boolean isPlaying(String uri){
265278
return isPlaying();
266279
}
267280

281+
/**
282+
* 判断是否自动播放
283+
* @return
284+
*/
285+
public boolean isAutoPlay() {
286+
return isAutoPlay;
287+
}
288+
289+
/**
290+
* 设置自动播放
291+
* @param autoPlay
292+
*/
293+
public void setAutoPlay(boolean autoPlay) {
294+
isAutoPlay = autoPlay;
295+
}
296+
268297
/**
269298
* 获取当前播放的地址
270299
* @return

0 commit comments

Comments
 (0)