private void setVideoScale(TextureView textureView, IjkMediaPlayer iMediaPlayer) {
int width = textureView.getWidth();
int height = textureView.getHeight();
int videoWidth = iMediaPlayer.getVideoWidth();
int videoHeight = iMediaPlayer.getVideoHeight();
// 剪切全屏
float widthRatio = videoWidth * 1f / width;
float HeightRatio = videoHeight * 1f / height;
float ratio = Math.min(widthRatio, HeightRatio);
float newWidth = videoWidth / ratio;
float newHeight = videoHeight / ratio;
textureView.getLayoutParams().width = (int) newWidth;
textureView.getLayoutParams().height = (int) newHeight;
textureView.setLayoutParams(textureView.getLayoutParams());
}
private void setVideoScale(TextureView textureView, IjkMediaPlayer iMediaPlayer) {
int width = textureView.getWidth();
int height = textureView.getHeight();
int videoWidth = iMediaPlayer.getVideoWidth();
int videoHeight = iMediaPlayer.getVideoHeight();
// 自适应
float widthRatio = videoWidth * 1f / width;
float HeightRatio = videoHeight * 1f / height;
float ratio = Math.max(widthRatio, HeightRatio);
float newWidth = videoWidth / ratio;
float newHeight = videoHeight / ratio;
textureView.getLayoutParams().width = (int) newWidth;
textureView.getLayoutParams().height = (int) newHeight;
textureView.setLayoutParams(textureView.getLayoutParams());
}