Instead of using MediaMetadataRetriever to get the width and height, I first retrieve a Bitmap from the video file and then setting the orientation according to the width and hight of the Bitmap, as shown below:private void rotateScreen() { try { //Create a new instance of MediaMetadataRetriever MediaMetadataRetriever retriever = new MediaMetadataRetriever(); //Declare the Bitmap Bitmap bmp; //Set the video Uri as data source for MediaMetadataRetriever retriever.setDataSource(this, mVideoUri); //Get one "frame"/bitmap - * NOTE - no time was set, so the first available frame will be used bmp = retriever.getFrameAtTime(); //Get the bitmap width and height videoWidth = bmp.getWidth(); videoHeight = bmp.getHeight(); //If the width is bigger then the height then it means that the video was taken in landscape mode and we should set the orientation to landscape if (videoWidth > videoHeight) { //Set orientation to landscape this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); } //If the width is smaller then the height then it means that the video was taken in portrait mode and we should set the orientation to portrait if (videoWidth < videoHeight) { //Set orientation to portrait this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); } } catch (RuntimeException ex) { //error occurred Log.e("MediaMetadataRetriever", "- Failed to rotate the video"); }} 这篇关于检测视频是否以人像/风景拍摄的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
09-14 14:21