|
|
@ -29,7 +29,7 @@ import tv.danmaku.ijk.media.widget.media.IMediaController;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* 播放控制器
|
|
|
|
* 播放控制器
|
|
|
|
*
|
|
|
|
* <p>
|
|
|
|
* Created by jiaozebo on 2017/6/11.
|
|
|
|
* Created by jiaozebo on 2017/6/11.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public class VideoControllerView extends FrameLayout implements IMediaController {
|
|
|
|
public class VideoControllerView extends FrameLayout implements IMediaController {
|
|
|
@ -62,11 +62,6 @@ public class VideoControllerView extends FrameLayout implements IMediaController
|
|
|
|
private ImageButton mFastButton; // 快进
|
|
|
|
private ImageButton mFastButton; // 快进
|
|
|
|
private ImageButton mRewindButton; // 快退
|
|
|
|
private ImageButton mRewindButton; // 快退
|
|
|
|
|
|
|
|
|
|
|
|
private long mReceivedBytes;
|
|
|
|
|
|
|
|
private long mReceivedPackets;
|
|
|
|
|
|
|
|
private long lastBitsMillis;
|
|
|
|
|
|
|
|
private long recordBeginTime;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private Handler mHandler = new MessageHandler(this);
|
|
|
|
private Handler mHandler = new MessageHandler(this);
|
|
|
|
|
|
|
|
|
|
|
|
private Runnable mSeekingPending;
|
|
|
|
private Runnable mSeekingPending;
|
|
|
@ -77,15 +72,6 @@ public class VideoControllerView extends FrameLayout implements IMediaController
|
|
|
|
show(sDefaultTimeout);
|
|
|
|
show(sDefaultTimeout);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// 全屏的点击事件
|
|
|
|
|
|
|
|
private OnClickListener mFullscreenListener = v -> {
|
|
|
|
|
|
|
|
doToggleFullscreen();
|
|
|
|
|
|
|
|
show(sDefaultTimeout);
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 录像的点击事件
|
|
|
|
|
|
|
|
private OnClickListener mRecordingListener = v -> show(sDefaultTimeout);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 滚动条的点击事件
|
|
|
|
// 滚动条的点击事件
|
|
|
|
private OnSeekBarChangeListener mSeekListener = new OnSeekBarChangeListener() {
|
|
|
|
private OnSeekBarChangeListener mSeekListener = new OnSeekBarChangeListener() {
|
|
|
|
public void onStartTrackingTouch(SeekBar bar) {
|
|
|
|
public void onStartTrackingTouch(SeekBar bar) {
|
|
|
@ -138,6 +124,9 @@ public class VideoControllerView extends FrameLayout implements IMediaController
|
|
|
|
|
|
|
|
|
|
|
|
int pos = mPlayer.getCurrentPosition();
|
|
|
|
int pos = mPlayer.getCurrentPosition();
|
|
|
|
pos -= 5000; // милисекунд
|
|
|
|
pos -= 5000; // милисекунд
|
|
|
|
|
|
|
|
if (pos < 0) {
|
|
|
|
|
|
|
|
pos = 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
mPlayer.seekTo(pos);
|
|
|
|
mPlayer.seekTo(pos);
|
|
|
|
setProgress();
|
|
|
|
setProgress();
|
|
|
|
|
|
|
|
|
|
|
@ -161,7 +150,9 @@ public class VideoControllerView extends FrameLayout implements IMediaController
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/** ==================== constructor ==================== */
|
|
|
|
/**
|
|
|
|
|
|
|
|
* ==================== constructor ====================
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
public VideoControllerView(Context context, AttributeSet attrs) {
|
|
|
|
public VideoControllerView(Context context, AttributeSet attrs) {
|
|
|
|
super(context, attrs);
|
|
|
|
super(context, attrs);
|
|
|
@ -188,10 +179,12 @@ public class VideoControllerView extends FrameLayout implements IMediaController
|
|
|
|
Log.i(TAG, TAG);
|
|
|
|
Log.i(TAG, TAG);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/** ==================== system Override ==================== */
|
|
|
|
/**
|
|
|
|
|
|
|
|
* ==================== system Override ====================
|
|
|
|
|
|
|
|
*/
|
|
|
|
/*
|
|
|
|
/*
|
|
|
|
* 发生在视图实例化的过程中,一般在activity的oncreate方法中,并且只有在布局文件中实例化才有会这个回调
|
|
|
|
* 发生在视图实例化的过程中,一般在activity的oncreate方法中,并且只有在布局文件中实例化才有会这个回调
|
|
|
|
* */
|
|
|
|
* */
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void onFinishInflate() {
|
|
|
|
public void onFinishInflate() {
|
|
|
|
super.onFinishInflate();
|
|
|
|
super.onFinishInflate();
|
|
|
@ -201,8 +194,8 @@ public class VideoControllerView extends FrameLayout implements IMediaController
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
/*
|
|
|
|
* 当发生轨迹球事件时触发该方法(貌似轨迹球是过去手机的按键)
|
|
|
|
* 当发生轨迹球事件时触发该方法(貌似轨迹球是过去手机的按键)
|
|
|
|
* */
|
|
|
|
* */
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public boolean onTrackballEvent(MotionEvent ev) {
|
|
|
|
public boolean onTrackballEvent(MotionEvent ev) {
|
|
|
|
show(sDefaultTimeout);
|
|
|
|
show(sDefaultTimeout);
|
|
|
@ -210,8 +203,8 @@ public class VideoControllerView extends FrameLayout implements IMediaController
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
/*
|
|
|
|
* 当发生触摸屏事件时触发该方法
|
|
|
|
* 当发生触摸屏事件时触发该方法
|
|
|
|
* */
|
|
|
|
* */
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public boolean onTouchEvent(MotionEvent event) {
|
|
|
|
public boolean onTouchEvent(MotionEvent event) {
|
|
|
|
show(sDefaultTimeout);
|
|
|
|
show(sDefaultTimeout);
|
|
|
@ -272,7 +265,9 @@ public class VideoControllerView extends FrameLayout implements IMediaController
|
|
|
|
return super.dispatchKeyEvent(event);
|
|
|
|
return super.dispatchKeyEvent(event);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/** ==================== IMediaController ==================== */
|
|
|
|
/**
|
|
|
|
|
|
|
|
* ==================== IMediaController ====================
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void hide() {
|
|
|
|
public void hide() {
|
|
|
@ -336,7 +331,6 @@ public class VideoControllerView extends FrameLayout implements IMediaController
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void setMediaPlayer(MediaController.MediaPlayerControl player) {
|
|
|
|
public void setMediaPlayer(MediaController.MediaPlayerControl player) {
|
|
|
|
mPlayer = player;
|
|
|
|
mPlayer = player;
|
|
|
|
|
|
|
|
|
|
|
|
updatePausePlay();
|
|
|
|
updatePausePlay();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -494,7 +488,7 @@ public class VideoControllerView extends FrameLayout implements IMediaController
|
|
|
|
if (isCompleted) {
|
|
|
|
if (isCompleted) {
|
|
|
|
int duration = mPlayer.getDuration();
|
|
|
|
int duration = mPlayer.getDuration();
|
|
|
|
final int progress = mProgress.getProgress();
|
|
|
|
final int progress = mProgress.getProgress();
|
|
|
|
Log.d(TAG,String.valueOf(duration));
|
|
|
|
Log.d(TAG, String.valueOf(duration));
|
|
|
|
|
|
|
|
|
|
|
|
mSeekingPending = new Runnable() {
|
|
|
|
mSeekingPending = new Runnable() {
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
@ -505,11 +499,8 @@ public class VideoControllerView extends FrameLayout implements IMediaController
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
postDelayed(mSeekingPending,500);
|
|
|
|
postDelayed(mSeekingPending, 500);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
mReceivedBytes = 0;
|
|
|
|
|
|
|
|
mReceivedPackets = 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
updatePausePlay();
|
|
|
|
updatePausePlay();
|
|
|
@ -553,7 +544,7 @@ public class VideoControllerView extends FrameLayout implements IMediaController
|
|
|
|
mProgress.setMax(duration);
|
|
|
|
mProgress.setMax(duration);
|
|
|
|
mProgress.setProgress(position);
|
|
|
|
mProgress.setProgress(position);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
if (position > mProgress.getProgress()){
|
|
|
|
if (position > mProgress.getProgress()) {
|
|
|
|
mProgress.setProgress(position);
|
|
|
|
mProgress.setProgress(position);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|