@Override public void onVideoSizeChanged(int width, int height, int unappliedRotationDegrees, float pixelWidthHeightRatio) { if (DEBUG) { Log.d(TAG, "onVideoSizeChanged() called with: width / height = [" + width + " / " + height + " = " + (((float) width) / height) + "], unappliedRotationDegrees = [" + unappliedRotationDegrees + "], pixelWidthHeightRatio = [" + pixelWidthHeightRatio + "]"); } aspectRatioFrameLayout.setAspectRatio(((float) width) / height); }
/** * Called when there's a change in the aspect ratio of the content being displayed. The default * implementation sets the aspect ratio of the content frame to that of the content, unless the * content view is a {@link SphericalSurfaceView} in which case the frame's aspect ratio is * cleared. * * @param contentAspectRatio The aspect ratio of the content. * @param contentFrame The content frame, or {@code null}. * @param contentView The view that holds the content being displayed, or {@code null}. */ protected void onContentAspectRatioChanged( float contentAspectRatio, @Nullable AspectRatioFrameLayout contentFrame, @Nullable View contentView) { if (contentFrame != null) { contentFrame.setAspectRatio( contentView instanceof SphericalSurfaceView ? 0 : contentAspectRatio); } }
@Override public void onVideoSizeChanged(int width, int height, int unappliedRotationDegrees, float pixelWidthHeightRatio) { if (contentFrame != null) { float aspectRatio = height == 0 ? 1 : (width * pixelWidthHeightRatio) / height; contentFrame.setAspectRatio(aspectRatio); } }
@Override public void onNewAspectRatio(float aspectRatio) { videoFrame.setAspectRatio(aspectRatio); }
private boolean setArtworkFromBitmap(Bitmap bitmap) { if (bitmap != null) { int bitmapWidth = bitmap.getWidth(); int bitmapHeight = bitmap.getHeight(); if (bitmapWidth > 0 && bitmapHeight > 0) { if (contentFrame != null) { contentFrame.setAspectRatio((float) bitmapWidth / bitmapHeight); } artworkView.setImageBitmap(bitmap); artworkView.setVisibility(VISIBLE); return true; } } return false; }
private boolean setArtworkFromBitmap(Bitmap bitmap) { if (bitmap != null) { int bitmapWidth = bitmap.getWidth(); int bitmapHeight = bitmap.getHeight(); if (bitmapWidth > 0 && bitmapHeight > 0) { if (contentFrame != null) { contentFrame.setAspectRatio((float) bitmapWidth / bitmapHeight); } artworkView.setImageBitmap(bitmap); artworkView.setVisibility(VISIBLE); return true; } } return false; }
@Override public void onVideoSizeChanged( int width, int height, int unappliedRotationDegrees, float pixelWidthHeightRatio) { if (contentFrame == null) { return; } float videoAspectRatio = (height == 0 || width == 0) ? 1 : (width * pixelWidthHeightRatio) / height; if (surfaceView instanceof TextureView) { // Try to apply rotation transformation when our surface is a TextureView. if (unappliedRotationDegrees == 90 || unappliedRotationDegrees == 270) { // We will apply a rotation 90/270 degree to the output texture of the TextureView. // In this case, the output video's width and height will be swapped. videoAspectRatio = 1 / videoAspectRatio; } if (textureViewRotation != 0) { surfaceView.removeOnLayoutChangeListener(this); } textureViewRotation = unappliedRotationDegrees; if (textureViewRotation != 0) { // The texture view's dimensions might be changed after layout step. // So add an OnLayoutChangeListener to apply rotation after layout step. surfaceView.addOnLayoutChangeListener(this); } applyTextureViewRotation((TextureView) surfaceView, textureViewRotation); } contentFrame.setAspectRatio(videoAspectRatio); }