【问题标题】:playing video with videoview用 videoview 播放视频
【发布时间】:2020-05-04 14:39:27
【问题描述】:

我正在尝试从 mp4 http url 在 vi​​deoview 中播放视频。 该活动仅配置为纵向,并且视频视图设置为在宽度和高度上都与父级匹配。 当视频播放时它是横向的,即使手机是纵向的并且方向被锁定为纵向。 当我尝试将 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();

有什么想法吗?

【问题讨论】:

  • 感谢您的回答,我的问题是它自己的视频文件。当我尝试播放另一个垂直视频时,它可以正常播放。我不知道第一个文件有什么问题,当我在 html5 视频标签中播放它时它正在工作并且我可以看到它是垂直的,但在 videoView 中它是水平的

标签: java android xamarin android-videoview


【解决方案1】:

嗯,我认为是因为你的布局,

一个视图不能在四个不同的方向上对齐,你试过了吗:

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

或者只是使用线性布局并匹配高度宽度。

如有疑问,请随时回复

【讨论】:

    【解决方案2】:

    在您的 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>
    

    【讨论】:

      【解决方案3】:

      你可以试试这个代码 对于 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);
      }
      

      我认为代码工作正常。如果您在下面有任何其他查询评论。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-05-24
        相关资源
        最近更新 更多