exoplay 不支持旋转,但您可以使用技巧: 解决方案一:旋转视图 解决方案二:按纹理视图矩阵旋转。我正在使用解决方案二,但是当您旋转成功纹理而不更新渲染帧时遇到了一些问题,您必须运行视频以更新新旋转。我的代码在编辑前预览旋转视频:
@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);
}
}
我只需要改变 AspectRatioFrameLayout 从港口到陆地的比例,希望它可以帮助你。applyTextureViewRotation 是 exo 的私有函数,你可以在源项目 exo 中找到它。也许 exoplayer 很快就会支持旋转预览视频