Jignesh Patel Jignesh Patel - 2 years ago 191
Android Question

How to detect orientation of recorded video in android

Hello friends I am new in android developing and i am facing some problem while i am working with camera in my app. I am developing app and in this app i am using the inbuilt functionality of camera. In my app camera will perform the task to capture video and then i save the captured video.

Now problem is that when i shoot video i want to know that in which orientation video is recorded? Because i am increasing or lapsing the speed of the video by using the library. And when i pass this recorded video in another activity this video is not coming as same as it was record. So Help me to resolve this problem.

Answer Source

You could try do something like this: (viewSource is your video source)

MediaPlayer mp = new MediaPlayer();
String orientation = "";
try {
  mp.setOnVideoSizeChangedListener(new OnVideoSizeChangedListener() {
      public void onVideoSizeChanged(MediaPlayer mp, int width, int height) {
          if(width < height){
              orientation = "vertical";
          } else {
              orientation = "horizontal";
} catch (IllegalArgumentException e) {
} catch (SecurityException e) {
} catch (IllegalStateException e) {
} catch (IOException e) {

You can see here for more variants: Detect orientation of a recorded video in android

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download