【问题标题】:How I can hide controls, full screen buttons in Youtube Player android API?如何在 Youtube Player android API 中隐藏控件、全屏按钮?
【发布时间】:2013-10-14 10:00:13
【问题描述】:

我正在尝试隐藏 YouTube 视频播放器 (api) 中的按钮。我用过

player.setShowFullscreenButton(false)

这成功隐藏了全屏按钮,但我没有找到隐藏控制按钮的方法——该按钮可以转到 YouTube 应用程序。

我尝试过使用

player.setPlayerStyle(PlayerStyle.MINIMAL);

这隐藏了所有按钮,但也改变了进度条,但我需要旧的进度条。

有什么帮助吗?

【问题讨论】:

    标签: android youtube-api android-youtube-api youtube-iframe-api


    【解决方案1】:

    您可以将播放器设为“Chromeless”播放器。应该这样做。

    【讨论】:

    • 但我想要 YouTubePlayer.PlayerStyle.DEFAULT 的所有控件,除了“YouTube”按钮。如何在 Android 中执行此操作。它在 iOS 和 Javascript 中是可行的。
    【解决方案2】:

    试试这个

    在您的 onInitializationSuccess 方法中使用此代码

    player.setPlayerStyle(YouTubePlayer.PlayerStyle.CHROMELESS);
    

    完整代码

    @Override
    public void onInitializationSuccess(YouTubePlayer.Provider provider,
                                        YouTubePlayer player, boolean wasRestored) {
        if (!wasRestored) {
    
            // loadVideo() will auto play video
            // Use cueVideo() method, if you don't want to play it automatically
            player.loadVideo(Config.YOUTUBE_VIDEO_CODE);
    
            // Hiding player controls
            player.setPlayerStyle(YouTubePlayer.PlayerStyle.CHROMELESS);
          //player.setPlayerStyle(YouTubePlayer.PlayerStyle.DEFAULT);
        }
    }
    

    注意:-

    1.用于显示所有交互式控件

    public static final YouTubePlayer.PlayerStyle DEFAULT

    2.用于隐藏所有交互控件

    public static final YouTubePlayer.PlayerStyle CHROMELESS

    3.仅显示时间栏和播放/暂停控件

    public static final YouTubePlayer.PlayerStyle MINIMAL

    更多信息请访问官方link

    【讨论】:

      【解决方案3】:

      我只知道这适用于 API 的 Youtube 播放器版本 1.2.2。仅隐藏 YOUTUBE 按钮。

      ((ViewGroup)((ViewGroup)((ViewGroup)((ViewGroup)((ViewGroup)((ViewGroup)((ViewGroup)((ViewGroup)findViewById(R.id.YOUR_VIDEO_PLAYER_ID)).getChildAt(0)).getChildAt(0))
                      .getChildAt(4)).getChildAt(0)).getChildAt(0)).getChildAt(3)).getChildAt(0)).getChildAt(1).setVisibility(View.GONE);
      

      【讨论】:

      • ClassCastException: ProgressBar cannot be cast to android.view.ViewGroup
      【解决方案4】:

      仅禁用全屏

      setShowFullscreenButton(布尔显示)

      显示或隐藏播放器控件上的全屏按钮。

      供参考See this link

      【讨论】:

        猜你喜欢
        • 2014-11-04
        • 2016-09-01
        • 2012-08-07
        • 1970-01-01
        • 2023-03-23
        • 1970-01-01
        • 2015-12-15
        • 2020-02-18
        • 2016-07-04
        相关资源
        最近更新 更多