Recently in an Android video player, there is a problem: when you switch to the next video, the middle will stay in the last video of the remnants of the screen. What's going on? I find a lot of information on the Internet, and finally found the reason: I use a custom Surfaceview to display the screen, switch video is not the Surfaceview display content to do processing. How to solve? Knowing the reason, that would be a good solution. First, when the video is switched on, the video is no longer displayed, and the player does not display the video content. I found this method in my Code: Mvideoview.setrender (0);
public void Setrender (int render) {
Switch (render) {
Case Render_none:
Setrenderview (NULL);
Break
Case Render_texture_view: {
Texturerenderview Renderview = new Texturerenderview (GetContext ());
if (Mmediaplayer! = null) {
Renderview.getsurfaceholder (). Bindtomediaplayer (Mmediaplayer);
Renderview.setvideosize (Mmediaplayer.getvideowidth (),
Mmediaplayer.getvideoheight ());
Renderview.setvideosampleaspectratio (
Mmediaplayer.getvideosarnum (),
Mmediaplayer.getvideosarden ());
Renderview.setaspectratio (Mcurrentaspectratio);
}
Setrenderview (Renderview);
Break
}
Case Render_surface_view: {
Surfacerenderview Renderview = new Surfacerenderview (GetContext ());
Setrenderview (Renderview);
Break
}
Default
LOG.E (TAG, String.Format (Locale.getdefault (),
"Invalid Render%d\n", render));
Break
}
}
public void Setrenderview (Irenderview renderview) {
if (Mrenderview! = null) {
if (Mmediaplayer! = null)
Mmediaplayer.setdisplay (NULL);
View Renderuiview = Mrenderview.getview ();
Mrenderview.removerendercallback (Mshcallback);
Mrenderview = null;
Removeview (Renderuiview);
}
if (Renderview = = null)
Return
Mrenderview = Renderview;
Renderview.setaspectratio (Mcurrentaspectratio);
if (mvideowidth > 0 && mvideoheight > 0)
Renderview.setvideosize (Mvideowidth, mvideoheight);
if (Mvideosarnum > 0 && mvideosarden > 0)
Renderview.setvideosampleaspectratio (Mvideosarnum, Mvideosarden);
View Renderuiview = Mrenderview.getview ();
Framelayout.layoutparams LP = new Framelayout.layoutparams (
FrameLayout.LayoutParams.WRAP_CONTENT,
FrameLayout.LayoutParams.WRAP_CONTENT, Gravity.center);
RENDERUIVIEW.SETLAYOUTPARAMS (LP);
AddView (Renderuiview);
Mrenderview.addrendercallback (Mshcallback);
Mrenderview.setvideorotation (Mvideorotationdegree);
}
Then, after the video is ready, the video is displayed: Initrenders ();
public void Initrenders () {
Mallrenders.clear ();
if (Msettings.getenablesurfaceview ())
Mallrenders.add (Render_surface_view);
if (Msettings.getenabletextureview ()
&& Build.VERSION.SDK_INT >= build.version_codes. Ice_cream_sandwich)
Mallrenders.add (Render_texture_view);
if (Msettings.getenablenoview ())
Mallrenders.add (Render_none);
if (Mallrenders.isempty ())
Mallrenders.add (Render_surface_view);
Mcurrentrender = Mallrenders.get (Mcurrentrenderindex);
Setrender (Mcurrentrender);
}
According to this logic, solve this problem.
The solution to the last video screen when the Android video player switches to the next video