Note that there are some explanatory texts on larger screens.

plurals
  1. POVideo aspect ratio is not correct, I set a ratio of 1.333 and the video has 1:1
    primarykey
    data
    text
    <p>I use a Frame Layout, on which i bind my video player like this:</p> <pre><code>private void initVideoPlayer(View root) { mVideoPlayer = new TextureViewVideoPlayer(width, height); mVideoPlayer.setOnErrorListener(this); mVideoPlayer.setOnPreparedListener(this); mVideoPlayer.setOnCompletionListener(this); mVideoPlayer.setOnBufferingUpdateListener(this); mVideoPlayer.setOnSeekCompleteListener(this); mVideoPlayer.setOnVideoSizeChangedListener(this); mVideoPlayer.bindView((FrameLayout) root.findViewById(R.id.videoFrame), 0); } </code></pre> <p>This is the onVideoSizeChanged function, from the TextureViewVideoPlayer:</p> <pre><code>@Override public void onVideoSizeChanged(MediaPlayer mp, int width, int height) { Log.i(TAG, "onVideoSizeChanged " + width + " ZZ " + height + " Display Height: " + displayheight + " --- REAL VIDEO RATIO: -- " + ((double) width / (double) height)); if (this.mOnVideoSizeChangedListener != null) this.mOnVideoSizeChangedListener.onVideoSizeChanged(this, width, height); if (width == 0 || height == 0) { mp.release(); Log.e(TAG, "invalid video width(" + width + ") or height(" + height + ")"); return; } double ratio = ((double) width / (double) height); if (displayheight &gt; height) { ratio = ((double) displayheight / (double) height); } else { ratio = ((double) height / (double) displayheight); } LayoutParams params = new FrameLayout.LayoutParams((int) (width * ratio), (int) (height * ratio)); // LayoutParams params = new FrameLayout.LayoutParams((width), // (height)); Log.i(TAG, "onVideoSizeChanged mod" + params.width + " ZZ " + params.height + " RATIO: " + ratio + " --- REAL RATIO: -- " + ((double) params.width / (double) params.height)); params.gravity = Gravity.CENTER; mTextureView.setLayoutParams(params); this.mTextureView.requestLayout(); } </code></pre> <p>As you can see, it takes the video width and height of the video, it calculates the ratio, then it takes the displays height, and makes a ratio to see how much bigger (or smaller) the video is than the screen, then it creates the params for the video, with that ratio, and sets this parameters on the textureView.</p> <p>In the xml, the VideoFrame i bind my player too has this: </p> <pre><code>&lt;FrameLayout android:id="@+id/videoFrame" android:layout_width="match_parent" android:layout_height="match_parent" android:fitsSystemWindows="true" &gt; &lt;/FrameLayout&gt; </code></pre> <p>Now, if I keep it like this, the video is stretched, and even though it looks like its a rectangle, a part from the top and bottom of the video disappear (being 1:1 the width and height are the same, and the height is bigger that the screen). Now, if I don't use the ratio, and create the parameters with the width and height of the video (640 x 480) It will be a small square. (ratio 1:1), and stretched. Any ideea how this could be avoided?</p> <p>PS: My texture view in fact is a Square Texture View, which had this onMeasure function:</p> <pre><code> @Override protected void onMeasure(int paramInt1, int paramInt2) { int i = View.MeasureSpec.getSize(paramInt1); setMeasuredDimension(i, i); } </code></pre> <p>I've changed it into: </p> <pre><code> @Override protected void onMeasure(int paramInt1, int paramInt2) { int i = View.MeasureSpec.getSize(paramInt1); int j = View.MeasureSpec.getSize(paramInt2); setMeasuredDimension(i, j); } </code></pre> <p>Hopefully, this fixes my issues.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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