Recorded video is played on Android Android device

I am making an Android Video app in which I record multiple videos and manage the videos in a list. The videos are taken correctly, but they were shown sideways (I mean I see the video in portrait mode if my device is indeed in landscape mode). Can anyone let me know how to solve this problem. I am using below code to write

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

      

And I will store the video in the Gallery. Any code related to custom video is also helpful. You can see what is my problem in the image below. I have tried many ways how to put setDisplayOrientation()

it as well setOrientationHint()

. I wonder if there is no solution at all to solve this problem? how many of them are being developed in video applications. Please help me.

I mentioned this and this one .

enter image description here

+3


source to share


3 answers


Confirm that you have an alternate layout in your main.xml file (Portrait and Landscape). This should normally take care of all orientations for your device. both xml files must have the same name (eg main.xml) in a different Layout folder.



+1


source


It would be a bit of a hack (although, according to this post , it is not possible to record videos in a different orientation), but for API level 14 and up, you can use Media Effects to rotate VideoView

.



+1


source


The entry code shown appears to be correct. I just tested the code on my Samsung S2 with ICS and the video plays in the correct orientation. You are not showing the code to play. Maybe where the problem is:

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 xml layout for video viewing 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 EXTRA_SCREEN_ORIENTATION to different values. On my device it didn't seem to make any difference, YMMV though. Here's the code, plus I threw in a few more additions since you asked for a nicer 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 many additional additions: http://developer.android.com/reference/android/provider/MediaStore.html#EXTRA_DURATION_LIMIT

0


source







All Articles