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?
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.
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......
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); } }); } });
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With