Matrix scale video on TextureView Android -


i'm trying play video exoplaye on textureview. in order scale , crop video fit view use matrix. custom view extends `textureview' here code:

@override public void onvideosizechanged(int width, int height, float pixelwidthheightratio) {     updatetextureviewsize(width, height);     log.v("exo", "onvideosizechanged() " +  width + "x" + height); }  private void updatetextureviewsize(float videowidth, float videoheight) {     float viewwidth = getwidth();     float viewheight = getheight();      float scalex = 1.0f;     float scaley = 1.0f;      float viewratio = viewwidth / viewheight;     float videoratio = videowidth / videoheight;     if (viewratio > videoratio) {         // video higher view         scaley = videoheight / videowidth;     } else {         //video wider view         scalex = videowidth / videoheight;     }      matrix matrix = new matrix();     matrix.setscale(scalex, scaley, viewwidth / 2, viewheight / 2);       settransform(matrix); } 

i had rectangular views , worked perfectly. views have 2 states: expanded (the old ones still rectangular) , collapsed (have smaller height.

so video stretched vertically in collapsed views.

for instance have view 1080x480 , video 360x640 looks video scaled , cropped 1080x1080 , stretched 1080x480.

what doing wrong here ?

upd: here screenshots: enter image description here

check updatetextureviewsize :

/**  * set display options  *  * @param layout <ul>  *               <li>{@link #video_layout_origin}  *               <li>{@link #video_layout_scale}  *               <li>{@link #video_layout_stretch}  *               <li>{@link #video_layout_zoom}  *               </ul>  */ public void updatetextureviewsize(int layout,float videowidth, float videoheight) {     relativelayout.layoutparams lp = (android.widget.relativelayout.layoutparams) getlayoutparams();     displaymetrics disp = m_context.getresources().getdisplaymetrics();     int windowwidth = disp.widthpixels, windowheight = disp.heightpixels;     float windowratio = windowwidth / (float) windowheight;     float videoratio = (float) videowidth / (float) videoheight;     m_isurfaceheight = videoheight;     m_isurfacewidth = videowidth;     if (video_layout_origin == layout && m_isurfacewidth < windowwidth && m_isurfaceheight < windowheight) {         lp.width = (int) (m_isurfaceheight * videoratio);         lp.height = m_isurfaceheight;     } else if (layout == video_layout_zoom) {         lp.width = windowratio > videoratio ? windowwidth : (int) (videoratio * windowheight);         lp.height = windowratio < videoratio ? windowheight : (int) (windowwidth / videoratio);     } else {         boolean full = layout == video_layout_stretch;         lp.width = (full || windowratio < videoratio) ? windowwidth : (int) (videoratio * windowheight);         lp.height = (full || windowratio > videoratio) ? windowheight : (int) (windowwidth / videoratio);         lp.leftmargin = (disp.widthpixels - lp.width) / 2;         lp.topmargin = (disp.heightpixels - lp.height) / 2;     }      lp.leftmargin = (disp.widthpixels - lp.width) / 2;     lp.topmargin = (disp.heightpixels - lp.height) / 2;      getholder().setfixedsize(m_isurfacewidth, m_isurfaceheight);      setlayoutparams(lp);      m_ivideolayout = layout; } 

Comments

Popular posts from this blog

Fail to load namespace Spring Security http://www.springframework.org/security/tags -

sql - MySQL query optimization using coalesce -

unity3d - Unity local avoidance in user created world -