我的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)

请引用以下链接以获取更多信息

https://developers.google.com/youtube/android/player/reference/com/google/android/youtube/player/YouTubePlayer#loadVideo(java.lang.String,%20int)

10-08 17:47