强制youTubePlayerFragment方向

时间:2018-01-12 16:20:49

标签: android kotlin android-youtube-api

我有一个只允许纵向方向的应用。我想强制将youtube视频设置为横向/水平方向,而不是全屏显示。我试过旋转包含视频的片段,它在一定程度上起作用(容器占据了景观的形状,但视频仍以纵向模式播放)。我无法将活动设置为横向,因为我需要视图的其余部分来保持其纵向布局。

以下是我初始化视频的代码:

    val youTubePlayerFragment = YouTubePlayerSupportFragment.newInstance()
    val transaction = childFragmentManager.beginTransaction()
    transaction.add(R.id.youtube_fragment, youTubePlayerFragment).commit()
    youTubePlayerFragment.initialize("API-KEY",

            object : YouTubePlayer.OnInitializedListener {

                override fun onInitializationSuccess(provider: YouTubePlayer.Provider,
                                                     youTubePlayer: YouTubePlayer, b: Boolean) {
                    // do any work here to cue video, play video, etc.
                    youTubePlayer.setFullscreen(false)
                    youTubePlayer.loadVideo("VID-ID")
                    youTubePlayer.setPlayerStyle(YouTubePlayer.PlayerStyle.CHROMELESS)
                    youTubePlayer.play()
                    youtube_fragment.setRotation(90.toFloat())

                    youTubePlayer.addFullscreenControlFlag(YouTubePlayer.FULLSCREEN_FLAG_ALWAYS_FULLSCREEN_IN_LANDSCAPE)
                }

                override fun onInitializationFailure(provider: YouTubePlayer.Provider,
                                                     youTubeInitializationResult: YouTubeInitializationResult) {
                    Log.e("vid", "error playing video")
                }
            }
    )

1 个答案:

答案 0 :(得分:0)

在新活动中打开视频并从清单强制活动布局?当你的视频让我们说是landsacape然后就是景观中的一切。