Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You should extends from the built-in video view. </p> <p>Call <code>setVideoSize</code> before video view is shown, you can get video size from thumbnail extracted from video.</p> <p>So that, when video view's <code>onMeasure</code> is called, both <code>mVideoWidth</code> &amp; <code>mVideoHeight</code> are > 0.</p> <p>If you want to account the height of controllers, you can do it yourself in the <code>onMeasure</code> method.</p> <p>Hope will help.</p> <pre><code>public class MyVideoView extends VideoView { private int mVideoWidth; private int mVideoHeight; public MyVideoView(Context context, AttributeSet attrs) { super(context, attrs); } public MyVideoView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); } public MyVideoView(Context context) { super(context); } public void setVideoSize(int width, int height) { mVideoWidth = width; mVideoHeight = height; } @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { // Log.i("@@@", "onMeasure"); int width = getDefaultSize(mVideoWidth, widthMeasureSpec); int height = getDefaultSize(mVideoHeight, heightMeasureSpec); if (mVideoWidth &gt; 0 &amp;&amp; mVideoHeight &gt; 0) { if (mVideoWidth * height &gt; width * mVideoHeight) { // Log.i("@@@", "image too tall, correcting"); height = width * mVideoHeight / mVideoWidth; } else if (mVideoWidth * height &lt; width * mVideoHeight) { // Log.i("@@@", "image too wide, correcting"); width = height * mVideoWidth / mVideoHeight; } else { // Log.i("@@@", "aspect ratio is correct: " + // width+"/"+height+"="+ // mVideoWidth+"/"+mVideoHeight); } } // Log.i("@@@", "setting size: " + width + 'x' + height); setMeasuredDimension(width, height); } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload