0

I want to crop youtube video in a circular view while playing. How can I achieve this? I have tried it by embedding it in a linear layout and then making the background of the layout as a circle but the youtube player view remains in the rectangular shape in this case.

 <LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@drawable/circle"
    android:gravity="center"
    >

<com.google.android.youtube.player.YouTubePlayerView
    android:id="@+id/youtube_view"
    android:layout_width="150dp"
    android:layout_height="150dp"
    />
</LinearLayout>

and background file

<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<solid
    android:color="#666666"/>
<size
    android:width="200dp"
    android:height="200dp"/>
</shape>
Rohan Sharma
  • 374
  • 4
  • 11

1 Answers1

1

First you create a CircleLayout class from below Link.

https://github.com/dmitry-zaitsev/CircleLayout/blob/master/src/ru/biovamp/widget/CircleLayout.java

Add this styleable into you values.

<declare-styleable name="CircleLayout">
    <attr name="innerRadius" format="dimension" />
    <attr name="sliceDivider" format="reference|color" />
    <attr name="innerCircle" format="reference|color" />
    <attr name="angleOffset" format="float" />
    <attr name="angleRange" format="float" />
    <attr name="layoutMode">
        <enum name="normal" value="1" />
        <enum name="pie" value="2" />
    </attr>
    <attr name="dividerWidth" format="dimension" />
</declare-styleable>

After set your YouTubePlayerView in your layout like below:-

<packageName.CircleLayout
        android:layout_width="300dp"
        android:layout_height="300dp"
        app:layoutMode="pie"
        app:angleOffset="90.0">

        <com.google.android.youtube.player.YouTubePlayerView
            android:id="@+id/youtube_player_view"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:scaleType="fitXY" />

    </packageName.CircleLayout>

Your YouTube View like below image:-

enter image description here

Nikunj Patel
  • 424
  • 2
  • 13