[英]playing video with videoview
我正在尝试从 mp4 http url 在 videoview 中播放视频。 该活动仅配置为纵向,并且视频视图设置为在宽度和高度上都匹配父项。 当视频播放时它是横向的,即使手机是纵向的并且方向被锁定为纵向。 当我尝试将 videoview 旋转设置为 90 时,视频不会播放,屏幕只是保持黑色,这是 xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<VideoView
android:id="@+id/vv1"
android:layout_alignParentTop="true"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
</RelativeLayout>
这是我在 onCreate 事件中使用的代码
VideoView vv = FindViewById<VideoView>(Resource.Id.vv1);
MediaController mediaController = new MediaController(this);
mediaController.SetAnchorView(vv);
vv.SetMediaController(mediaController);
vv.SetVideoURI(Android.Net.Uri.Parse(url));
vv.RequestFocus();
vv.Start();
任何想法?
嗯,我认为因为你的布局,
一个视图不能在四个不同的方向上对齐,你试过吗:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<VideoView
android:id="@+id/vv1"
android:layout_alignParentTop="true"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
或者只是使用线性布局并匹配高度宽度。
如果您有任何疑问,请随时回复
在您的 videoView 活动中尝试此代码
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
和布局应该像
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<VideoView
app:layout_constraintDimensionRatio="4:3"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:id="@+id/vv"/>
<ProgressBar
android:layout_width="50dp"
android:layout_height="50dp"
android:id="@+id/progrss"
android:visibility="gone"
android:layout_centerInParent="true"/>
</RelativeLayout>
</LinearLayout>
你可以试试这个代码 XML 布局
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<VideoView
android:id="@+id/vv1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerVertical="true"
/>
</RelativeLayout>
对于全屏视图,您可以将此代码添加到您的活动中
private void hideSystemUi() {
playerView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE
| View.SYSTEM_UI_FLAG_FULLSCREEN
| View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
}
我认为代码工作正常。 如果您在下面有任何其他查询评论。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.