如何在我的应用程序上自动播放 youtube 视频?
How to auto play youtube video on my app?
我的 youtube api 工作正常,正在播放视频。
我只想在打开 video.kt
activity 播放器时自动播放视频。
video.kt
val youtubefragment: YouTubePlayerSupportFragment = supportFragmentManager.findFragmentById(R.id.youtube_fragment)
as YouTubePlayerSupportFragment
youtubefragment.initialize(API_KEY,object:YouTubePlayer.OnInitializedListener{
override fun onInitializationSuccess(provider: YouTubePlayer.Provider?, player: YouTubePlayer?, wasRestored: Boolean){
if(player == null) return
if (wasRestored)
player.play()
else{
player.cueVideo(value)
player.setPlayerStyle(YouTubePlayer.PlayerStyle.DEFAULT)
}
}
override fun onInitializationFailure(p0: YouTubePlayer.Provider?, p1: YouTubeInitializationResult?) {
}
要自动播放 Youtube 视频,请使用
player.loadVideo(value, 0) //replace 0 with milliseconds for delay in autoplay
而不是
player.cueVideo(value)
更多信息请参考以下link
我的 youtube api 工作正常,正在播放视频。
我只想在打开 video.kt
activity 播放器时自动播放视频。
video.kt
val youtubefragment: YouTubePlayerSupportFragment = supportFragmentManager.findFragmentById(R.id.youtube_fragment)
as YouTubePlayerSupportFragment
youtubefragment.initialize(API_KEY,object:YouTubePlayer.OnInitializedListener{
override fun onInitializationSuccess(provider: YouTubePlayer.Provider?, player: YouTubePlayer?, wasRestored: Boolean){
if(player == null) return
if (wasRestored)
player.play()
else{
player.cueVideo(value)
player.setPlayerStyle(YouTubePlayer.PlayerStyle.DEFAULT)
}
}
override fun onInitializationFailure(p0: YouTubePlayer.Provider?, p1: YouTubeInitializationResult?) {
}
要自动播放 Youtube 视频,请使用
player.loadVideo(value, 0) //replace 0 with milliseconds for delay in autoplay
而不是
player.cueVideo(value)
更多信息请参考以下link