如何在Youtube Player Android API中隐藏控件和全屏按钮?

10

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

player.setShowFullscreenButton(false)

这样做可以成功隐藏全屏按钮,但我没有找到方法来隐藏控制按钮--那个按钮可以跳转到YouTube应用程序。

我尝试使用

player.setPlayerStyle(PlayerStyle.MINIMAL);

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

有什么帮助吗?

4个回答

7
你可以将播放器初始化为“无界面”播放器。这样应该就可以了。

1
但我想要 YouTubePlayer.PlayerStyle.DEFAULT 的所有控件,除了 "YouTube" 按钮。在 Android 中如何做到这一点。这在 iOS 和 Javascript 中是可行的。 - GreenROBO

1

试一下

在你的onInitializationSuccess方法中使用以下代码

player.setPlayerStyle(YouTubePlayer.PlayerStyle.CHROMELESS);

Full code

@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

更多信息请访问官方链接


0

禁用全屏仅需执行以下操作

setShowFullscreenButton(boolean show)

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

参考链接:请查看此链接


0

我只知道这适用于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 - Hamzeh Soboh

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接