Java 使用videoview播放视频
我正在尝试从mp4 http url在videoview中播放视频。 活动仅配置为纵向,视频视图设置为在宽度和高度上与父级匹配。 当播放视频时,即使手机是纵向的,视频也是横向的,并且方向锁定在纵向上。 当我尝试将videoview旋转设置为90时,视频不会播放,屏幕只会保持黑色 这是xmlJava 使用videoview播放视频,java,android,xamarin,android-videoview,Java,Android,Xamarin,Android Videoview,我正在尝试从mp4 http url在videoview中播放视频。 活动仅配置为纵向,视频视图设置为在宽度和高度上与父级匹配。 当播放视频时,即使手机是纵向的,视频也是横向的,并且方向锁定在纵向上。 当我尝试将videoview旋转设置为90时,视频不会播放,屏幕只会保持黑色 这是xml <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="
<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();
VideoView vv=findviewbyd(Resource.Id.vv1);
MediaController MediaController=新的MediaController(此);
mediaController.SetAnchorView(vv);
vv.SetMediaController(mediaController);
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"
/>
或者只使用线性布局并匹配高度和宽度
如果您有任何疑问,请随时回来。我想,由于您的布局 视图不能在四个不同的方向上对齐,是否尝试过:
<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>
在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>
我认为代码工作得很好。如果您在下面有任何其他查询注释。您可以尝试此代码
用于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>
我认为代码工作得很好。如果您在下面有任何其他查询意见。谢谢您的回答,我的问题是视频文件本身。当我尝试播放另一个垂直视频时,它播放得很好。我不知道第一个文件有什么问题,当我在html5视频标签中播放它时,它正在工作,我可以垂直看到它,但在视频视图中它是水平的。谢谢你的回答,我的问题是视频文件本身。当我尝试播放另一个垂直视频时,它播放得很好。我不知道第一个文件有什么问题,当我在html5视频标签中播放它时,它正在工作,我可以看到它是垂直的,但在视频视图中它是水平的