【问题标题】:Force Video to play in Portrait Orientation only using MediaPlayer and VideoView仅使用 MediaPlayer 和 VideoView 强制视频以纵向播放
【发布时间】:2011-06-16 20:10:35
【问题描述】:

我正在编写一个将在我的 SD 卡上播放视频文件的活动。我有这个代码工作。

视频的方向取决于我的手机是垂直还是水平。我想强制我的视频水平播放(如默认播放器)。有没有办法做到这一点?

我的代码:

布局

<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>

视频代码:

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);
   mVideoView.setVideoURI(Uri.parse(videoUrl));
   mVideoView.requestFocus(); 
   mVideoView.start();
}

有什么想法吗?

【问题讨论】:

  • 我只是想尝试锁定方向...我会尝试并回复。
  • 是的,这似乎成功了。
  • 能否请您发布答案。

标签: android video orientation media-player android-videoview


【解决方案1】:

为了完整起见,我将回答这个问题。这个之前已经发过好几次了。转到您的 Android 清单并将其添加到您要锁定方向的活动声明中

android:screenOrientation="portrait"

【讨论】:

  • 视图仍然是横向的。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-10-18
  • 1970-01-01
相关资源
最近更新 更多