【发布时间】:2015-10-12 14:00:23
【问题描述】:
我正在尝试在TextureView 上播放带有ExoPlaye 的视频。为了缩放和裁剪视频以适合视图,我使用矩阵。我的自定义视图扩展了 `TextureView' 这是我的代码:
@Override
public void onVideoSizeChanged(int width, int height, float pixelWidthHeightRatio) {
updateTextureViewSize(width, height);
Log.v("EXO", "onVideoSizeChanged() " + width + "x" + height);
}
private void updateTextureViewSize(float videoWidth, float videoHeight) {
float viewWidth = getWidth();
float viewHeight = getHeight();
float scaleX = 1.0f;
float scaleY = 1.0f;
float viewRatio = viewWidth / viewHeight;
float videoRatio = videoWidth / videoHeight;
if (viewRatio > videoRatio) {
// video is higher than view
scaleY = videoHeight / videoWidth;
} else {
//video is wider than view
scaleX = videoWidth / videoHeight;
}
Matrix matrix = new Matrix();
matrix.setScale(scaleX, scaleY, viewWidth / 2, viewHeight / 2);
setTransform(matrix);
}
我有一个矩形视图,它工作得很好。但是现在视图有两种状态:展开(仍然是矩形的旧视图)和折叠(高度更小。
所以现在视频在这些折叠视图中被垂直拉伸。
例如,我查看了1080x480 和视频360x640,但看起来视频已缩放并裁剪为1080x1080,然后拉伸为1080x480。
我在这里做错了什么?
【问题讨论】:
-
能不能也加个截图?
标签: android video scale exoplayer