在Android中隐藏媒体控制器的播放暂停按钮 [英] Hide play pause button of media controller in android

查看:462
本文介绍了在Android中隐藏媒体控制器的播放暂停按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的活动中有视频视图,也有MediaController,但是我想从媒体控制器中隐藏播放暂停按钮.

I have video View in my activity also having MediaController but I want to hide the play pause button from media controller.

这是我的代码:

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

请给我建议解决方案.

推荐答案

我设法实现了同样的目标.默认情况下,媒体控制器不会公开任何方法来隐藏播放/暂停控件.因此,我们必须遍历Media Controller的子视图,获取所需的视图,并对该视图做任何您想做的事情. 就我而言,我是按照以下方式进行的

I have managed to achieve the same. By default Media Controller doesn't expose any method to hide the play/pause control. Hence we have to loop through the child views of Media Controller, get the desired view and do whatever you want to do with that view. In my case, i did in following way

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(); } });

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的子类,它在位置0处具有一个LinearLayout作为子视图组(viewGroupLevel1),再次viewGroupLevel1包含两个子视图组,从中获得了子视图组(viewGroupLevel2) viewGroupLevel1在位置0处.现在在viewGroupLevel2中,获取位置2的视图,该视图实际上是一个图像按钮(播放/暂停"按钮).现在,您可以轻松隐藏它.干杯!

To explain my code, Basically Media Controller is a subclass of FrameLayout and it has one LinearLayout as a child viewgroup (viewGroupLevel1) at position 0, again viewGroupLevel1 contains two children view groups, out of which get the viewgroup (viewGroupLevel2) from viewGroupLevel1 at position 0. Now in viewGroupLevel2 get the view of position 2 which is actually an imagebutton (Play/Pause button). Now you can easily hide it. Cheers!

这篇关于在Android中隐藏媒体控制器的播放暂停按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆