android - 仅使用 MediaPlayer 和 VideoView 强制视频以纵向播放

标签 android video orientation media-player android-videoview

我正在编写一个将在我的 SD 卡上播放视频文件的 Activity 。我可以使用此代码。

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

我的代码:

布局

<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 list 并将其添加到您要锁定方向的 Activity 声明中

android:screenOrientation="portrait"

关于android - 仅使用 MediaPlayer 和 VideoView 强制视频以纵向播放,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6377982/

相关文章:

c++ - 如何从H264中的ffmpeg读取sei未注册的用户数据?

audio - 将 youtube-dl 与 ffmpeg 一起使用时,什么合并扩展 (mkv/mp4) 可以获得最佳音质

android - 在对话框android中播放视频

ios - 将图像旋转 3*Double.pi/2 使图像不出现 (swift3)

java - 从 HttpPost Android 中提取 URL

android - 我丢失了用于签署我的 apk 的 keystore 。可以在play store重新上传吗?

android - 我的 Android 应用出现奇怪的 sharedPreference 问题

java - 比较android中的两个EditTexts字符串

android - 获取 Android 设备的方向

android - "Landscape"和 "Landscape-reverse"方向的不同布局