且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

检测记录的视频在机器人的方向

更新时间:2021-11-07 09:05:14

在太多的努力,我才知道,媒体播放器提供的高度和宽度的视频文件,从中我们可以鳍片出视频的旋转。

After too much effort i came to know that media player provides height and width of video file from which we can fin out rotation of video.

MediaPlayer mp = new MediaPlayer();
  try {
      mp.setDataSource(viewSource);
      mp.prepare();
      mp.setOnVideoSizeChangedListener(new OnVideoSizeChangedListener() {
          @Override
          public void onVideoSizeChanged(MediaPlayer mp, int width, int height) {

              int orientation = -1;

              if(width < height){
                  orientation = 0;
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);}
              else{
                  orientation = 1;
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);}

          }
      });
  } catch (IllegalArgumentException e) {
      e.printStackTrace();
  } catch (SecurityException e) {
      e.printStackTrace();
  } catch (IllegalStateException e) {
      e.printStackTrace();
  } catch (IOException e) {
      e.printStackTrace();
  }