gpt4 book ai didi

android - 在android中隐藏媒体 Controller 的播放暂停按钮

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:50:24 25 4
gpt4 key购买 nike

我的 Activity 中有视频 View 也有 MediaController,但我想隐藏媒体 Controller 的播放暂停按钮。

这是我的代码:

MediaController mediaController =  new MediaController(this,false);
videoHolder.setMediaController(mediaController);
mediaController.setAnchorView(videoHolder);

请给我建议解决方案。

最佳答案

我已经设法实现了同样的目标。默认情况下,媒体 Controller 不公开任何隐藏播放/暂停控件的方法。因此,我们必须遍历 Media Controller 的 subview ,获取所需的 View ,然后对该 View 做任何您想做的事情。

在我的例子中,我按照以下方式做了 ->

videoPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mediaPlayer) {
LinearLayout viewGroupLevel1 = (LinearLayout) media_Controller.getChildAt(0);
LinearLayout viewGroupLevel2 = (LinearLayout) viewGroupLevel1.getChildAt(0);
View view = viewGroupLevel2.getChildAt(2);
view.setVisibility(View.GONE);
videoPlayer.start();
}
}); `

为了解释我的代码,基本上 Media Controller 是 FrameLayout 的子类,它有一个 LinearLayout 作为位置 0 的 subview 组(viewGroupLevel1),viewGroupLevel1 再次包含两个 subview 组,从中获取 View 组(viewGroupLevel2) viewGroupLevel1 在位置 0。现在在 viewGroupLevel2 中获取位置 2 的 View ,它实际上是一个图像按钮(播放/暂停按钮)。现在您可以轻松隐藏它。干杯!

关于android - 在android中隐藏媒体 Controller 的播放暂停按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15763699/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com