13

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

Davi
  • 1,031
  • 12
  • 21
  • You could make a drawable resource with blacked out rounded corners and a fully transparent middle, then overlay that inside an `ImageView` on top of your video player? – privatestaticint Jan 24 '19 at 20:58

3 Answers3

29

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);
Davi
  • 1,031
  • 12
  • 21
10

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>
dastan
  • 892
  • 10
  • 17
2

On your FrameLayout, remove the padding then call clipToOutline() on that view e.g

player_view_layout.clipToOutline()

By default the view background is used as the outline provider for a view, so if the background drawable has rounded corners, all content in FrameLayout will be clipped to match.

https://developer.android.com/training/material/shadows-clipping

veritas1
  • 8,740
  • 6
  • 27
  • 37