3

I am doing an Android Video App in which I record few Videos and manage videos in the list. Videos are taken properly but they were shown in sideways (what i mean is I can see video in portrait mode if my device is actually in Landscape mode). Can any one let me know how to solve this issue. I am using below code to record

Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_VIDEO_CAPTURE);
startActivityForResult(cameraIntent,120);

And I will store the videos in Gallery. Any Code related to Custom Video Recording are also helpful. You can see what is my problem in the below image. I have tried many ways like putting setDisplayOrientation() and also setOrientationHint(). I wonder that there is no solution at all for this problem? then how many developing the Video Apps. Please someone help me.

I referred this and this links also.

enter image description here

Community
  • 1
  • 1
TNR
  • 5,839
  • 3
  • 33
  • 62

3 Answers3

1

Confirm you have an alternate layout out in your main.xml file (Portrait and Landscape). That should normaly take care of both orientations for your device. both xml files should have the same name (eg main.xml) in different Layout folder.

user1978601
  • 53
  • 1
  • 7
  • Can you give the example code if you have it. I am not getting what you are saying and when I tried as you said still getting the problems. – TNR Feb 21 '13 at 06:10
  • Am saying that it could just be a minor orientation issue since your code is running ok. USe Ctrl+F11 to alternate the orientations of your emulator, see if it works on either landscape or portrait. – user1978601 Mar 03 '13 at 23:42
1

It would be a bit of a hack (though according to this post, there is no way to record the video in a different orientation), but for API level 14 and above, you can use Media Effects to rotate your VideoView.

Community
  • 1
  • 1
Phil
  • 35,852
  • 23
  • 123
  • 164
0

The recording code you show seems correct. I just tested the code on my Samsung S2 with ICS, and the video plays back in the correct orientation. You don't show the code for the play back. Maybe that's where the problem lies:

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == 120) { // i personally prefer using a constant here
        VideoView videoView = (VideoView) findViewById(R.id.videoView);
        videoView.setVideoURI(data.getData());
        videoView.start();
    }
}

The layout xml for the videoView is very simple:

<VideoView
    android:id="@+id/videoView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"/>

If the above doesn't work you can also try setting the EXTRA_SCREEN_ORIENTATION to different values. On my device it didn't seem to make a difference, though YMMV. Here's the code, plus I threw in some more extras since you've asked for more custom video recording code:

private static final int RECORD_VIDEO = 120;

private void startRecording() {
    Intent cameraIntent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
    cameraIntent.putExtra(MediaStore.EXTRA_SCREEN_ORIENTATION, ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    cameraIntent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 0); // low quality
    cameraIntent.putExtra(MediaStore.EXTRA_DURATION_LIMIT, 5); // limit to 5 seconds
    startActivityForResult(cameraIntent, RECORD_VIDEO);
}

There are plenty more extras: http://developer.android.com/reference/android/provider/MediaStore.html#EXTRA_DURATION_LIMIT

Bernd S
  • 1,278
  • 1
  • 11
  • 18