Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MediaController positioning over VideoView

Tags:

android

I have a VideoView that takes up the top half of the Activity in portrait orientation with the bottom half of the screen showing some images and text. I am playing a rtsp video stream in the video view when the Activity starts. I have attached a MediaController to the VideoView via the following code:

    MediaController controller = new MediaController(this);     controller.setAnchorView(this.videoView);     controller.setMediaPlayer(this.videoView);     this.videoView.setMediaController(controller); 

When I tap the VideoView to bring up the MediaController on the screen I expected the playback controls to appear overlaying the bottom area of the VideoView (the bottom of the MediaController even with the bottom of the VideoView). Instead the MediaController pops up lower down on the screen, overlaying some of the graphics and text I have below the VideoView.

Are there some additional steps I need to take to get the MediaController to appear where I want it to on the screen?

like image 763
Mark B Avatar asked Sep 10 '10 17:09

Mark B


People also ask

What is MediaController in Android?

android.widget.MediaController. A view containing controls for a MediaPlayer. Typically contains the buttons like "Play/Pause", "Rewind", "Fast Forward" and a progress slider. It takes care of synchronizing the controls with the state of the MediaPlayer. The way to use this class is to instantiate it programmatically.

How to set MediaController with VideoView in Android?

Just define the MediaController object in on create and then add the view to that otherwise the error will like adding a view in a null object reference......


1 Answers

Setting the anchor view will only work if the videoview size is known - it will not be upon init. But you can do something like this:

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);             }         });     } }); 
like image 158
bk138 Avatar answered Oct 03 '22 03:10

bk138