1
votes

I'm trying to play a video in videoview from mp4 http url. the activity is configured for portrait only and the videoview set to match parent in both width and height. when the video is playing it is landscape even the phone is portrait and the orientation is locked on portrait. when I try to set the videoview rotation to 90, the video is not played and the screen just stays black this is the 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>

this is the code that I use in onCreate event

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();

any idea?

3
thanks for the answers, my problem was the video file it self. when i’m trying to play another vertical video, it is playing fine. I don’t know what is wrong with the first file, when I play it in html5 video tag it is working and I can see it vertical, but in videoView it is horizontal - Ronen Rimon

3 Answers

0
votes

Well, I think that because of your Layout,

A View cannot be aligned in four different directions, have you tried:

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

Or just with a linear layout and match the height width.

Feel free to get back if you have queries

0
votes

Try this code in your videoView activity

  getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);

and layout should be like

<?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>
0
votes

You can try this code For XML Layout

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

And for full screen view, you can add this code on your activity

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);
}

I think the code work fine. If you have any other query comment below.