我正在编写一个将在我的 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/