Hide play pause button of media controller in android

非 Y 不嫁゛ 提交于 2019-12-10 17:25:42

问题


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

Here is my code:

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

Please suggest me solutions.


回答1:


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

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!




回答2:


You can see http://www.phonesdevelopers.com/1765331/

    MediaController mc = new MediaController(this);  
    mc.setVisibility(View.INVISIBLE);  
    videoView.setMediaController(mc);  

it's worked




回答3:


Try it ( not sure)

Use OnPreparedListener and in the callback onPrepared do your hide inderectly, like:

@Override
public void onPrepared (MediaPlayer mp) 
{
    int childs = mediaController.getChildCount();
    for (int i = 0; i < childs; i++)
    {
        View child = mediaController.getChildAt (i);
        child.setVisibility (View.GONE);
    }
}


来源:https://stackoverflow.com/questions/15763699/hide-play-pause-button-of-media-controller-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!