开发者

Force Video to play in Portrait Orientation only using MediaPlayer and VideoView

I am writing an activity that will play a video file on my SD card. I have this code working.

The orientation of the video is based on if my phone is vertical or horizontal. I want to force my video to play horizontally (like the default player). Is there a way to do this?

My code:

Layout

<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content" android:orientation="horizontal">

  <VideoView android:id="@+id/VideoView" 
    android:layout_width="fill_parent" android:layout_height="fill_parent">
  </VideoView>

</LinearLayout>

Video Code:

protected void onCreate(Bundle savedInstanceState) 
{
   super.onCreate(savedInstanceState);
   this.setContentView(R.layout.video_view);
   mVideoView = (VideoView)this.findViewById(R.id.VideoView);
   String videoUrl = "/mnt/sdcard-ext" + "/Videos/Wildlife.wmv";
   MediaController mc = new MediaController(this);
   mc.setAnchorView(mVideoView);
   mVideoView.setMediaController(mc);
   mVideoVie开发者_JS百科w.setVideoURI(Uri.parse(videoUrl));
   mVideoView.requestFocus(); 
   mVideoView.start();
}

Any ideas?


For the sake of completeness I'll answer this question. This has been posted several times before. Go to your Android Manifest and add this to the activity declaration that you want to lock the orientation

android:screenOrientation="portrait"
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜