exoplay don't support rotate but you can use trick:
solution one : rotate view
solution two : rotate by matrix of texture view.
I'm use solution two but had some problem when you rotate success texture not update render frame you must run video for update new rotate.
my code for preview rotate video before edit:
@Override
public void onAspectRatioUpdated(float targetAspectRatio, float naturalAspectRatio, boolean aspectRatioMismatch) {
new Handler(Looper.getMainLooper()).post(() -> {
TextureView textureView = (TextureView) getPlayerView().getVideoSurfaceView();
textureView.setVisibility(View.INVISIBLE);
applyTextureViewRotation(textureView, mPresenter.getRotation());
textureView.setVisibility(View.VISIBLE);
mPresenter.checkPlayAgain();
});
}
public void checkPlayAgain() {
if (mPlayer == null) {
isResume = false;
return;
}
if (isResume) {
mPlayer.seekTo(cachePos);
mPlayer.setPlayWhenReady(true);
} else {
mPlayer.seekTo(cachePos + 100);
mPlayer.seekTo(cachePos - 100);
}
}
public static void applyTextureViewRotation(TextureView textureView, int textureViewRotation) {
float textureViewWidth = textureView.getWidth();
float textureViewHeight = textureView.getHeight();
if (textureViewWidth == 0 || textureViewHeight == 0 || textureViewRotation == 0) {
textureView.setTransform(null);
} else {
Matrix transformMatrix = new Matrix();
float pivotX = textureViewWidth / 2;
float pivotY = textureViewHeight / 2;
transformMatrix.postRotate(textureViewRotation, pivotX, pivotY);
// After rotation, scale the rotated texture to fit the TextureView size.
RectF originalTextureRect = new RectF(0, 0, textureViewWidth, textureViewHeight);
RectF rotatedTextureRect = new RectF();
transformMatrix.mapRect(rotatedTextureRect, originalTextureRect);
transformMatrix.postScale(
textureViewWidth / rotatedTextureRect.width(),
textureViewHeight / rotatedTextureRect.height(),
pivotX,
pivotY);
textureView.setTransform(transformMatrix);
}
}
i just need change ratio of AspectRatioFrameLayout from port to land, hope it can help you. applyTextureViewRotation is private funtion of exo you can find it in source project exo. Maybe exoplayer will support rotate preview video soon