如何以纵向模式显示视频?

时间:2015-01-31 06:07:04

标签: android xml video portrait

我想在另一个活动中显示我拍摄的视频,但问题是当我播放该视频时,它以横向模式显示,即使我只想显示肖像。

在屏幕截图中,您可以看到捕获的视频以横向方式播放,但它应以纵向模式播放。

捕获的屏幕:enter image description here

public class AndroidVideoViewExample extends Activity {

    private VideoView myVideoView;
    private int position = 0;
    private ProgressDialog progressDialog;
    private MediaController mediaControls;

    @Override
    protected void onCreate(final Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        // Get the layout from video_main.xml
        setContentView(R.layout.videodemo);

        if (mediaControls == null) {
            mediaControls = new MediaController(AndroidVideoViewExample.this);
        }

        // Find your VideoView in your video_main.xml layout
        myVideoView = (VideoView) findViewById(R.id.video_view);

        // Create a progressbar
        progressDialog = new ProgressDialog(AndroidVideoViewExample.this);
        // Set progressbar title
        progressDialog.setTitle("JavaCodeGeeks Android Video View Example");
        // Set progressbar message
        progressDialog.setMessage("Loading...");

        progressDialog.setCancelable(false);
        // Show progressbar
        progressDialog.show();

        try {
            myVideoView.setMediaController(mediaControls);
            myVideoView.setVideoURI(Uri.parse(android.os.Environment.getExternalStorageDirectory()+AppConstants.GAME_IMAGE_DIR+"/myvideo1.mp4"));

        } catch (Exception e) {
            Log.e("Error", e.getMessage());
            e.printStackTrace();
        }

        myVideoView.requestFocus();
        myVideoView.setOnPreparedListener(new OnPreparedListener() {
            // Close the progress bar and play the video
            public void onPrepared(MediaPlayer mp) {
                progressDialog.dismiss();
                myVideoView.seekTo(position);
                if (position == 0) {
                    myVideoView.start();
                } else {
                    myVideoView.pause();
                }
            }
        });

    }
}

Xml文件是:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="fill_parent"
    android:layout_gravity="center"
    android:layout_height="fill_parent" >

    <VideoView
        android:id="@+id/video_view"
        android:layout_width="720px"
        android:layout_height="720px"
        android:layout_gravity="center|center_vertical" />

</FrameLayout>

0 个答案:

没有答案