The solution to the last video screen when the Android video player switches to the next video

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.