17

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?

2

3 Answers 3

18

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);
                                    }
                                    });
                            }
          });
1
  • This is the answer actually work! No need to add MediaPlayer in XML layout. Just setAnchorView while VideoView while preparing itself. In case someone want to implement his own media controller check out stackoverflow.com/questions/3686729/…
    – Robert
    Nov 20, 2014 at 8:25
0

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

3
  • 4
    But even with this, the MediaController still appears at the bottom of the screen Aug 11, 2011 at 19:14
  • 2
    I think this is also dependent on several other factors like what Layout you are using in your XML
    – Ronnie
    Oct 24, 2011 at 17:11
  • Yeah might be. Bcoz I usually use Relative layouts only Mar 5, 2012 at 12:39
-1

/*var mediaController:MediaController? = null

videoView is reference to VideoView in layout file. */

videoView.setOnPreparedListener(OnPreparedListener { mp ->
            mp.setOnVideoSizeChangedListener { mp, width, height -> 
                   
                 mediaController = MediaController(this@ActivityName)

                videoView.setMediaController(mediaController)
    
               mediaController?.setAnchorView(videoView)
 
            }
        })
`

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.