Reputation: 54322
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?
Upvotes: 17
Views: 13628
Reputation: 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)
}
})
`
Upvotes: -1
Reputation: 3088
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);
}
});
}
});
Upvotes: 18
Reputation: 54322
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
Upvotes: 0