I have recyclerView with different type of items, and one of the item include youtube video ,I'm using YoutubePlayer .When I'm clicking on the video it starts playing but after a millisecond it stops.If I change to full screen mode it plays as expected. I receive this log
YouTube video playback stopped due to unauthorized overlay on top of player. The YouTubePlayerView is obscured by android.widget.FrameLayout It's item of recyclerView which contain youtubePlayer
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<fragment
android:id="@+id/youtubeFragment"
android:name="com.google.android.youtube.player.YouTubePlayerSupportFragment"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</android.support.constraint.ConstraintLayout>
val youtubeFragment = MainActivity.getMainActivity(context)?.supportFragmentManager?.findFragmentById(R.id.youtubeFragment)
youtubeFragment.initialize(KEY,
object : YouTubePlayer.OnInitializedListener {
override fun onInitializationSuccess(provider: YouTubePlayer.Provider, youTubePlayer: YouTubePlayer, b: Boolean) {
youTubePlayer.loadVideo("5xVh-7ywKpE")
}
override fun onInitializationFailure(provider: YouTubePlayer.Provider,
youTubeInitializationResult: YouTubeInitializationResult) {
}
})
Even I have tried commit fragment in class but it does not make difference
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<FrameLayout
android:id="@+id/youtubeFragment"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</android.support.constraint.ConstraintLayout>
val fragmentManager = MainActivity.getMainActivity(viewBinding.root.context)?.supportFragmentManager
val fragmentTransaction = fragmentManager?.beginTransaction()
//add a fragment
val youtubeFragment = YouTubePlayerSupportFragment()
fragmentTransaction?.add(R.id.youtubeFragment, youtubeFragment)
fragmentTransaction?.commit()
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">
<data>
<variable
name="toolbarViewModel"
type="se.ica.handla.ToolbarViewModel" />
</data>
<android.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/windowBackground"
android:fitsSystemWindows="true"
tools:context="se.ica.handla.MainActivity">
<include
android:id="@+id/toolbarLayout"
layout="@layout/toolbar_top_level"
app:toolbarViewModel="@{toolbarViewModel}" />
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_anchor="@+id/toolbarLayout"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<android.support.v7.widget.RecyclerView
android:id="@+id/news_list"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
</android.support.design.widget.CoordinatorLayout>
</layout>