I am working on android application where I am showing Youtube video by using youtube sdk. I want to hide suggestions which comes at the end of the video. I have implemented YouTubePlayer.PlayerStyle.MINIMAL
, which hides all buttons, but still recommendations/suggestions are coming at the end of the video. I am using YouTubeAndroidPlayerApi.jar
.
My code is given below, kindly guide me to fix this issue. Thanks
class YoutubeActivity : AppCompatActivity(), YouTubePlayer.OnInitializedListener {
private var videoId: String = ""
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_youtube)
videoId = intent.getStringExtra("videoId")
val youTubePlayerFragment = supportFragmentManager.findFragmentById(R.id.official_player_view) as YouTubePlayerSupportFragment?
youTubePlayerFragment?.initialize(getString(R.string.youtube_apikey), this)
}
override fun onInitializationSuccess(provider: YouTubePlayer.Provider, youTubePlayer: YouTubePlayer, wasRestored: Boolean) {
if (!wasRestored) {
youTubePlayer.setPlayerStyle(YouTubePlayer.PlayerStyle.MINIMAL)
youTubePlayer.setFullscreen(true)
youTubePlayer.loadVideo(videoId, 1)
youTubePlayer.setShowFullscreenButton(false)
}
}
override fun onInitializationFailure(provider: YouTubePlayer.Provider, youTubeInitializationResult: YouTubeInitializationResult) {
if (youTubeInitializationResult.isUserRecoverableError) {
youTubeInitializationResult.getErrorDialog(this, YouTube.RECOVERY_DIALOG_REQUEST).show()
} else {
val errorMessage = String.format(
"There was an error initializing the YouTubePlayer (%1\$s)",
youTubeInitializationResult.toString()
)
Toast.makeText(this, errorMessage, Toast.LENGTH_LONG).show()
}
}
}
My XML file:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
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"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorPrimary"
tools:context=".components.tutorial.fragments.YoutubeActivity">
<fragment
android:id="@+id/official_player_view"
android:name="com.google.android.youtube.player.YouTubePlayerSupportFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>