gpt4 book ai didi

android - 使用Youtube SDK Android在YouTube视频的末尾隐藏相关视频

转载 作者:行者123 更新时间:2023-12-03 06:08:24 25 4
gpt4 key购买 nike

我正在使用youtube sdk在Android应用程序上显示Youtube视频。我想隐藏视频末尾的建议。我已经实现了YouTubePlayer.PlayerStyle.MINIMAL,它隐藏了所有按钮,但是建议/建议仍在视频末尾出现。我正在使用YouTubeAndroidPlayerApi.jar

我的代码如下,请指导我解决此问题。谢谢

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()
}
}
}

我的XML文件:
<?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>

最佳答案

您可以尝试添加YouTubePlayer。 PlayerStateChangeListener,添加onVideoEnded()方法,然后放置youtubePlayer.seekToMillis(0)我不确定它是否会工作,我从未在Android上使用过此库。

关于android - 使用Youtube SDK Android在YouTube视频的末尾隐藏相关视频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60718200/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com