3

YouTubePlayerSupportFragment inside NestedScrollView with bottom-sheet behaviour scrolling on its own after youtube onLoaded() is called.

YouTubePlayerSupportFragment scrolling the bottom-sheet up and onLayoutChild() method is called in BottomSheetBehavior.

public boolean onLayoutChild(CoordinatorLayout parent, V child, int layoutDirection )

If I return simply from onLayoutChild() i.e returning true directly, in MyBottomSheetBehavior, video doesn't play and static image is shown in youtube_view like thumbnail image without any video control views like play/pause, fullscreen views etc.

Have a look below:

ezgif.com-video-to-gifde6cf08fedd42916.gif

Find my code below to initialize the youtube player:

val youTubePlayerFragment = YouTubePlayerSupportFragment.newInstance()
    //Initialize YouTube Player
    youTubePlayerFragment.initialize(DEVLOPERKEY, object : YouTubePlayer.OnInitializedListener {
        override fun onInitializationSuccess(provider: YouTubePlayer.Provider, youTubePlayer: YouTubePlayer, b: Boolean) {
            //youTubePlayer.setFullscreenControlFlags(0);
            isInitialize = true
            mYouTubePlayer = youTubePlayer
            mYouTubePlayer.cueVideo("videoId")
        }

        override fun onInitializationFailure(provider: YouTubePlayer.Provider, youTubeInitializationResult: YouTubeInitializationResult) {
            isInitialize = false
            player = null
        }
    })
    val transaction = supportFragmentManager.beginTransaction()
    transaction.add(R.id.youtube_view, youTubePlayerFragment as Fragment).commit()

activity_main:

<androidx.coordinatorlayout.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/mainLayoutContainer">

    <include
    android:id="@+id/sub_view_layout"
    layout="@layout/sub_view"/>

    <com.google.android.material.appbar.AppBarLayout
    android:id="@+id/appbar_layout"
    android:layout_width="match_parent"
    android:layout_height="@dimen/actionbar_height"
    android:background="#00000000"
    android:paddingStart="0dp"
    android:paddingEnd="0dp"
    android:visibility="gone"
    android:theme="@style/AppTheme.AppBarOverlay"/>

    <androidx.appcompat.widget.Toolbar
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="@dimen/actionbar_height"
    app:titleMarginBottom="0dp"
    android:background="#00000000"
    app:titleMarginTop="0dp"
    android:layout_marginStart="0dp">
        <ImageView
        android:id="@+id/ic_close"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/ic_close"
        android:contentDescription="@null"/>
    </androidx.appcompat.widget.Toolbar>
</androidx.coordinatorlayout.widget.CoordinatorLayout>

sub_view:

<androidx.core.widget.NestedScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@drawable/drawer_background"
        android:id="@+id/nested_scroll_view"
        android:orientation="vertical"
        android:fitsSystemWindows="true"
        app:layout_behavior="com.testjava.customui.MyBottomSheetBehavior">

    <androidx.constraintlayout.widget.ConstraintLayout
            android:id="@+id/main_layout"
            android:layout_width="match_parent"
            android:layout_height="match_parent">

        <!--YouTube Player Start -->
        <FrameLayout
                android:id="@+id/youtube_view_rl"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent"
                android:layout_marginTop="24dp">
            <FrameLayout
                    android:id="@+id/youtube_view"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"/>
        </FrameLayout>
        <!--YouTube Player End -->
    </androidx.constraintlayout.widget.ConstraintLayout>
</androidx.core.widget.NestedScrollView>
Glorfindel
  • 21,988
  • 13
  • 81
  • 109
Sumit Sharma
  • 231
  • 2
  • 8

0 Answers0