本篇博客Demo链接:http://download.csdn.net/download/g_ying_jie/9960488
第一步、创建一个MediaView的xml布局,详见Demo的media_view.xml文件
第二步、创建MediaView类,直接继承Framelayout,并关联布局
public class MediaView extends FrameLayout implements View.OnClickListener, SeekBar.OnSeekBarChangeListener, MediaPlayer.OnPreparedListener, View.OnTouchListener {
private ImageView media_play;
private ImageView media_fullscreen;
private TextView media_total_time;
private TextView media_current_time;
private SeekBar media_seekBar;
private MediaControllerListener listener;
private VideoView videoView;
private ProgressBar progressBar;
private Context context;
private RelativeLayout media_controller;
private int progress;
private boolean isHorizontal = false;
private boolean fullscreen = false;
private boolean isPause = false;
private Timer timer;
//间隔一秒更新一次SeekBar进度,SeekBar的max值取之于videoView.getDuration()
private Handler handler = new Handler() {
@Override
public void handleMessage(Message msg) {
switch (msg.what) {
case 1000:
if (videoView.isPlaying())
media_seekBar.setProgress(videoView.getCurrentPosition());
break;
}
}
};
public MediaView(@NonNull Context context) {
super(context);
loadRoot(context);
}
public MediaView(@NonNull Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
loadRoot(context);
}
public MediaView(@NonNull Context context, @Nullable