Skip to content

Commit

Permalink
control layout dismiss delay millis control
Browse files Browse the repository at this point in the history
  • Loading branch information
xieguangwei committed Apr 16, 2018
1 parent 92c49db commit 3767df6
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 24 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ allprojects {
### Step 2. Add the dependency
```
dependencies {
compile 'com.github.xieguangwei:MyCustomMediaPlayer:1.6'
compile 'com.github.xieguangwei:MyCustomMediaPlayer:1.7'
}
```
### 感兴趣的可以下载demo看下,[同款的基于ExoPlayer封装的播放器>>>](https://github.com/xieguangwei/MyCustomExoPlayer)
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class AppConfig extends Application {
@Override
public void onCreate() {
super.onCreate();
MyMediaPlayerDelegate.getInstance().initApp(this).initLog(true);
MyMediaPlayerDelegate.getInstance().initApp(this).initLog(true).initControlDismissDelayMillis(1000);
Utils.init(this);
}
}
2 changes: 1 addition & 1 deletion custommediaplayer/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ android {
minSdkVersion 15
targetSdkVersion 26
versionCode 1
versionName "1.6"
versionName "1.7"

testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
public class MyMediaPlayerDelegate {
private static MyMediaPlayerDelegate instance;
private Application app;
private int millis;

public static MyMediaPlayerDelegate getInstance() {
if (instance == null) {
synchronized (MyMediaPlayerDelegate.class) {
Expand All @@ -20,16 +22,27 @@ public static MyMediaPlayerDelegate getInstance() {
}
return instance;
}

public MyMediaPlayerDelegate initApp(Application app) {
this.app = app;
return this;
}

public MyMediaPlayerDelegate initLog(boolean shouldShowLog) {
KLog.init(shouldShowLog);
return this;
}

public MyMediaPlayerDelegate initControlDismissDelayMillis(int millis) {
this.millis = millis;
return this;
}

public Application getApp() {
return app;
}

public int getDelayMillis() {
return this.millis == 0 ? 4000 : this.millis;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import com.xgw.custommediaplayer.entity.VideoBean;
import com.xgw.custommediaplayer.listener.VideoPlayListener;
import com.xgw.custommediaplayer.utils.MyMediaPlayManager;
import com.xgw.custommediaplayer.utils.MyMediaPlayerDelegate;
import com.xgw.custommediaplayer.utils.MyVideoControlManager;
import com.xgw.custommediaplayer.utils.PlayModeUtils;
import com.xgw.custommediaplayer.utils.VideoCoverUtils;
Expand Down Expand Up @@ -169,7 +170,7 @@ public void onClick(View v) {
playOrPause();
} else if (id == reloadRl.getId()) {
//播放出错,重新加载
playSpecifiedVideo(playUrl,coverUrl);
playSpecifiedVideo(playUrl, coverUrl);
} else if (id == fullScreenIv.getId()) {
//全屏/退出全屏
if (listener != null) {
Expand Down Expand Up @@ -298,7 +299,7 @@ public void onItemChildClick(BaseQuickAdapter adapter, View view, int position)
String coverUrl = videoBean.getCoverUrl();
videoListAdapter.setPlay(url, MyMediaPlayer.this);
currentProgress = 0;
playSpecifiedVideo(url,coverUrl);
playSpecifiedVideo(url, coverUrl);
}
});

Expand All @@ -311,11 +312,11 @@ public void onItemChildClick(BaseQuickAdapter adapter, View view, int position)
@Override
public boolean onTouch(View v, MotionEvent event) {
int action = event.getAction();
if (action == MotionEvent.ACTION_DOWN) {
if (action == MotionEvent.ACTION_DOWN || action == MotionEvent.ACTION_MOVE) {
hasTouchedListOrSeekBar = true;
} else if (action == MotionEvent.ACTION_UP) {
mHandler.removeCallbacks(mHideRunnable);
mHandler.postDelayed(mHideRunnable, 2000);
mHandler.postDelayed(mHideRunnable, MyMediaPlayerDelegate.getInstance().getDelayMillis() / 2);
hasTouchedListOrSeekBar = false;
}
return false;
Expand All @@ -326,11 +327,11 @@ public boolean onTouch(View v, MotionEvent event) {
@Override
public boolean onTouch(View v, MotionEvent event) {
int action = event.getAction();
if (action == MotionEvent.ACTION_DOWN) {
if (action == MotionEvent.ACTION_DOWN || action == MotionEvent.ACTION_MOVE) {
hasTouchedListOrSeekBar = true;
} else if (action == MotionEvent.ACTION_UP) {
mHandler.removeCallbacks(mHideRunnable);
mHandler.postDelayed(mHideRunnable, 2000);
mHandler.postDelayed(mHideRunnable, MyMediaPlayerDelegate.getInstance().getDelayMillis() / 2);
hasTouchedListOrSeekBar = false;
}
return false;
Expand All @@ -347,19 +348,19 @@ public void setVideoList(List<VideoBean> videoList) {
for (int i = 0; i < videoList.size(); i++) {
VideoBean item = videoList.get(i);
if (item.isPlaying()) {
setPlayUrl(item.getUrl(),item.getCoverUrl());
setPlayUrl(item.getUrl(), item.getCoverUrl());
break;
}
}
if (TextUtils.isEmpty(playUrl)) {
setPlayUrl(videoList.get(0).getUrl(),videoList.get(0).getCoverUrl());
setPlayUrl(videoList.get(0).getUrl(), videoList.get(0).getCoverUrl());
videoListAdapter.setPlay(playUrl, this);
}
}
loadCoverUrl();
}

private void setPlayUrl(String playUrl,String coverUrl) {
private void setPlayUrl(String playUrl, String coverUrl) {
this.playUrl = playUrl;
this.coverUrl = TextUtils.isEmpty(coverUrl) ? playUrl : coverUrl;
}
Expand All @@ -372,7 +373,7 @@ public void onSurfaceTextureAvailable(SurfaceTexture surfaceTexture, int i, int
mSurface = new Surface(surfaceTexture);//连接MediaPlayer和TextureView两个对象
isTextureAvailable = true;
//设置第一次打开时的播放器
playSpecifiedVideo(playUrl,coverUrl);
playSpecifiedVideo(playUrl, coverUrl);
}

@Override
Expand Down Expand Up @@ -417,8 +418,8 @@ private void loadCoverUrl() {
*
* @param url
*/
public void initPlayUrl(String url,String coverUrl) {
setPlayUrl(url,coverUrl);
public void initPlayUrl(String url, String coverUrl) {
setPlayUrl(url, coverUrl);
//没设置正在播放的视频,默认播放第一个视频
if (TextUtils.isEmpty(playUrl)) {
onErrorHandle(new Exception("initPlayUrl时视频地址为空!!!"));
Expand Down Expand Up @@ -456,8 +457,8 @@ private void onErrorHandle(Exception e) {
*
* @param url
*/
public void playSpecifiedVideo(String url,String coverUrl) {
setPlayUrl(url,coverUrl);
public void playSpecifiedVideo(String url, String coverUrl) {
setPlayUrl(url, coverUrl);
//没设置正在播放的视频,默认播放第一个视频
if (TextUtils.isEmpty(playUrl)) {
onErrorHandle(new Exception("playSpecifiedVideo时视频地址为空!!!"));
Expand Down Expand Up @@ -562,15 +563,15 @@ private void onCompleteHandle() {
int playMode = PlayModeUtils.getPlayMode();
//单曲循环模式---一直播放该视频
if (PlayModeUtils.getPlayMode() == PlayMode.PLAY_MODE_SINGLE_CYCLE) {
playSpecifiedVideo(playUrl,coverUrl);
playSpecifiedVideo(playUrl, coverUrl);
} else if (playMode == PlayMode.PLAY_MODE_LIST_CYCLE) {//列表循环模式---播放完最后一个视频播放第一个视频
for (int i = 0; i < videoListAdapter.getData().size(); i++) {
VideoBean videoBean = videoListAdapter.getData().get(i);
if (videoBean != null && videoBean.isPlaying()) {
if (i < videoListAdapter.getData().size() - 1) {
playSpecifiedVideo(videoListAdapter.getData().get(i + 1).getUrl(),videoListAdapter.getData().get(i + 1).getCoverUrl());
playSpecifiedVideo(videoListAdapter.getData().get(i + 1).getUrl(), videoListAdapter.getData().get(i + 1).getCoverUrl());
} else {
playSpecifiedVideo(videoListAdapter.getData().get(0).getUrl(),videoListAdapter.getData().get(0).getCoverUrl());
playSpecifiedVideo(videoListAdapter.getData().get(0).getUrl(), videoListAdapter.getData().get(0).getCoverUrl());
}
break;
}
Expand All @@ -580,7 +581,7 @@ private void onCompleteHandle() {
VideoBean videoBean = videoListAdapter.getData().get(i);
if (videoBean != null && videoBean.isPlaying()) {
if (i < videoListAdapter.getData().size() - 1) {
playSpecifiedVideo(videoListAdapter.getData().get(i + 1).getUrl(),videoListAdapter.getData().get(i + 1).getCoverUrl());
playSpecifiedVideo(videoListAdapter.getData().get(i + 1).getUrl(), videoListAdapter.getData().get(i + 1).getCoverUrl());
} else {
coverIv.setVisibility(VISIBLE);
btnPlay.setVisibility(VISIBLE);
Expand Down Expand Up @@ -677,7 +678,7 @@ public void playOrPause() {
btnPlay.setBackgroundResource(R.drawable.play_pause);
//开始播放(新的)
//显示TextureView,回调onSurfaceTextureAvailable方法,开始执行新的播放操作
playSpecifiedVideo(playUrl,coverUrl);
playSpecifiedVideo(playUrl, coverUrl);
}
setControlVisibility(GONE, GONE, GONE);
}
Expand All @@ -691,7 +692,7 @@ public void setControlVisibility(int btnPlayVisibility, int playProgressVisibili
playProgressLl.setVisibility(playProgressVisibility);
videoListRl.setVisibility(videoListVisibility);
removeCallbacks(mHideRunnable);
postDelayed(mHideRunnable, 4000);
postDelayed(mHideRunnable, MyMediaPlayerDelegate.getInstance().getDelayMillis());
}

public boolean isControlVisibility() {
Expand Down Expand Up @@ -814,7 +815,7 @@ public void onResume() {
setPlayModelImage();
if (!isFirstEnter && isTextureAvailable) {
btnPlay.setBackgroundResource(R.drawable.play_pause);
playSpecifiedVideo(playUrl,coverUrl);
playSpecifiedVideo(playUrl, coverUrl);
}
isFirstEnter = false;
}
Expand Down

0 comments on commit 3767df6

Please sign in to comment.