MediaController positioning over VideoView

后端 未结 10 1840
半阙折子戏
半阙折子戏 2020-12-02 07:19

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 v

10条回答
  •  难免孤独
    2020-12-02 07:27

    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);
                }
            });
        }
    });
    

提交回复
热议问题