跟随此https://stackoverflow.com/a/44324039/1427037https://inducesmile.com/android/android-camera2-api-example-tutorial/但是camera2 API仍然可以在Samsung设备android 9.0 OS中提供扩展的Preview。许多stackoverflow解决方案已经尝试过,但是没有优势。有什么帮助吗?注意:无法将相机API与SurfaceHolder一起使用。
选中此一项
@Override
public void setVideoURI(Uri uri) {
super.setVideoURI(uri);
MediaMetadataRetriever retr = new MediaMetadataRetriever();
retr.setDataSource(uri.getPath());
String height = retr.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_HEIGHT);
String width = retr.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_WIDTH);
try {
videoRealH = Integer.parseInt(height);
videoRealW = Integer.parseInt(width);
} catch (NumberFormatException e) {
e.printStackTrace();
}
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
int width = getDefaultSize(0, widthMeasureSpec);
int height = getDefaultSize(0, heightMeasureSpec);
if (height > width) {
if (videoRealH > videoRealW) {
mVideoHeight = height;
mVideoWidth = width;
} else {
mVideoWidth = width;
float r = videoRealH / (float) videoRealW;
mVideoHeight = (int) (mVideoWidth * r);
}
} else {
if (videoRealH > videoRealW) {
mVideoHeight = height;
float r = videoRealW / (float) videoRealH;
mVideoWidth = (int) (mVideoHeight * r);
} else {
mVideoHeight = height;
mVideoWidth = width;
}
}
if (videoRealH == videoRealW && videoRealH == 1) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
} else {
setMeasuredDimension(mVideoWidth, mVideoHeight);
}
}