If you write the player, you must first consider the playback time and progress bar refresh problem as for play and pause is simply tune the API
Live playback time Progress bar update
Case Update_time:
int progress = control_seekbar.getprogress ();
Control_play_time.settext (stringutils
. Generatetime (Progress * 1000)
+ "/"
+ Stringutils.generatetime (total_time * 1000));
if (progress = = Total_time) {
Mvideoview.stopplayback ();
Mvideoview.pause ();
Mhandler.removecallbacks (Hidecontrol);
Mhandler.removecallbacks (UpdateTime);
Finish ();
}
Break
Case Hide_control:
Startalphaanimation (Ll_play_control, 1, 0);
Break
Case Show_control:
Startalphaanimation (Ll_play_control, 1, 1);
Mhandler.postdelayed (Hidecontrol, 5000);
Break
Here I'm using handler refresh UI
Hide Controller
Private Runnable Hidecontrol = new Runnable () {
@Override
public void Run () {
Mhandler.sendemptymessage (Hide_control);
Controlisshow = false;
}
};
Update play time and progress bar
Private Runnable updatetime = new Runnable () {
@Override
public void Run () {
Control_seekbar.setprogress (++seekbarprogress);
Mhandler.sendemptymessage (Update_time);
Mhandler.postdelayed (this, 1000);
}
};
/**
* Initialize player Controller
*/
private void Initlivecontrol () {
Control_play_pause.setimageresource (R.drawable.icon_live_pause);
Total_time = Info.getplay_time ();//This is the total time I get to play the video
Control_seekbar.setmax (int) total_time);//Gross position time is set to Seekbar maximum value is for fast forward and the progress bar refreshes when the time to calculate some
Control_play_time.settext (stringutils.generatetime (0 * 1000) + "/"
+ Stringutils.generatetime (total_time * 1000));
Ll_play_control.setvisibility (view.visible);
Update Time and progress bar
Mhandler.postdelayed (updatetime, 1000);
Hide the controller 5 seconds after the page is first entered
Mhandler.postdelayed (Hidecontrol, 5000);
Play Pause button click event
Control_play_pause.setonclicklistener (this);
Here is the setting Seekbar drag event here because of its own project reasons there are several places that you can't use here I used the handler delay operation to achieve the function of the timer is to let the player's controller in a certain period of time to hide
Control_seekbar
. Setonseekbarchangelistener (New Onseekbarchangelistener () {
@Override
public void Onstoptrackingtouch (SeekBar SeekBar) {
int progress = seekbar.getprogress ();
Seekbarprogress = progress;
Mvideoview.seekto (Progress * 1000);
Mhandler.postdelayed (updatetime, 0);
Mhandler.postdelayed (Hidecontrol, 5000);
}
@Override
public void Onstarttrackingtouch (SeekBar SeekBar) {
Mhandler.removecallbacks (UpdateTime);
Mhandler.removecallbacks (Hidecontrol);
}
@Override
public void onprogresschanged (SeekBar SeekBar,
int progress, Boolean fromuser) {
}
});
}
At the same time, the following is a string (HH:MM:ss | | MM:SS) converted to milliseconds at that time on the Internet to find a half-day did not find suitable later simply wrote a of course it is very simple for many people here just for some new debut of the Friends to solve recover from fatigue
Convert time to milliseconds
public static long Generatemills (String time) {
string[] split = Time.split (":");
if (split.length = = 2) {
Only seconds
Long minutes = Long.parselong (split[0]);
Long seconds = Long.parselong (split[1]);
return seconds * + minutes * 60 * 1000;
} else if (split.length = = 3) {
sometimes seconds.
Long hours = Long.parselong (split[0]);
Long minutes = Long.parselong (split[1]);
Long seconds = Long.parselong (split[2]);
return seconds * + minutes * 60 * 60 * 1000;
}
return 1000;
}
Android Custom Player