Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make a rounded Exoplayer PlayerView in Android

Hi I am trying to create a rounded video player, and I am using the Exoplaye2 library. I am putting the PLayerView inside a rounded FrameLayout, but don't know how to make the PlayerView itself rounded. I have tried this but it is not working, I even created a rounded_shape_drawable and added it to the background of the Playeview, but it is not working (basically, setting the background for a PlayeView is not working at all).

Below is my simple layout file:

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_gravity="center_horizontal"
    android:layout_marginBottom="25dp"
    android:layout_weight="4"
    android:gravity="center"
    android:orientation="horizontal"
    android:weightSum="1">

    <FrameLayout
        android:id="@+id/player_view_layout"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="0.6"
        android:padding="10dp"
        android:background="@drawable/rounded_video_layout">

        <com.google.android.exoplayer2.ui.PlayerView

            android:id="@+id/exoplayer_player_view"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:fastforward_increment="@integer/exoplayer_playback_fastforward_increment_ms"
            app:resize_mode="fill"
            app:rewind_increment="@integer/exoplayer_playback_rewind_increment_ms"
            app:show_timeout="@integer/exoplayer_show_control_timeout_ms"
            app:use_artwork="true"
            app:use_controller="false">

        </com.google.android.exoplayer2.ui.PlayerView>

    </FrameLayout>

</LinearLayout>

And below is my current output:

enter image description here

Any help will be appreciated

like image 247
Davi Avatar asked Jan 24 '19 20:01

Davi


2 Answers

After a long search, I wasn't able to make rounded corners PlayerView or ImageView in xml only (I don't think it is possible). So I decided to do it in java. Below is the code:

playerView.setOutlineProvider(new ViewOutlineProvider() {
            @Override
            public void getOutline(View view, Outline outline) {
                outline.setRoundRect(0, 0, view.getWidth(), view.getHeight(), 15);
            }
        });

        playerView.setClipToOutline(true);
like image 132
Davi Avatar answered Sep 21 '22 13:09

Davi


May be you can use CardView like this and PlayerView surface_type must be texture_view.

<android.support.v7.widget.CardView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:cardCornerRadius="8dp"
    app:cardElevation="0dp">

    <com.google.android.exoplayer2.ui.PlayerView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:surface_type="texture_view" 
        app:use_controller="false" />

</android.support.v7.widget.CardView>
like image 43
dastan Avatar answered Sep 18 '22 13:09

dastan