Ronen Rimon
Ronen Rimon

Reputation: 9

playing video with videoview

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?

Upvotes: 1

Views: 851

Answers (3)

Nayan Sarder
Nayan Sarder

Reputation: 532

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.

Upvotes: 0

keven
keven

Reputation: 45

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>

Upvotes: 0

FreakyAli
FreakyAli

Reputation: 16449

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

Upvotes: 0

Related Questions