How to re-position the MediaController?

孤人 提交于 2019-12-03 15:43:53

问题


I have been using mediaController for my app.

By default, the Media Controller is displayed at the bottom of the screen.

Is there a way to display the Media Controller in the middle of the screen instead?


回答1:


Placing the mediacontroller only works if the video size is known. Thus you'll have to do:

video.setOnPreparedListener(new OnPreparedListener() {
    @Override
    public void onPrepared(MediaPlayer mp) {
            mp.setOnVideoSizeChangedListener(new OnVideoSizeChangedListener() { 
                                    @Override
                                    public void onVideoSizeChanged(MediaPlayer mp, int width, int height) {
                                          /*
                                           *  add media controller
                                           */
                                          mc = new MediaController(YourActivity.this);;
                                          video.setMediaController(mc);
                                          /*
                                           * and set its position on screen
                                           */
                                          mc.setAnchorView(video);
                                    }
                                    });
                            }
          });



回答2:


At last I got it..

   mediaController.setAnchorView(findViewById(R.id.main_audio_view));

Using this snippet we can re position the mediacontroller to be placed at a particular position based on the layout id or an view's id



来源:https://stackoverflow.com/questions/6093756/how-to-re-position-the-mediacontroller

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