MediaController positioning over VideoView

后端 未结 10 1846
半阙折子戏
半阙折子戏 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

    this is the first time I answer a question in stackoverflow, I only insert a VideoView inside a FrameLayout with same measures both. MediaController will be at the bottom of the FrameLayout. This worked for me:

    main_activity.XML:

               
    
                
    
            
    

    MainActivity.java:

    @Override
    public void onClick(View v) {
        int i = v.getId();
    
        if(i == R.id.select_video){
            selectVideo();
        }
    
    private void selectVideo(){
        //this code is to get videos from gallery:
        Intent galleryIntent = new Intent(Intent.ACTION_GET_CONTENT);
        galleryIntent.addCategory(Intent.CATEGORY_OPENABLE);
        galleryIntent.setAction(Intent.ACTION_GET_CONTENT);
        galleryIntent.setType("video/*");
        startActivityForResult(galleryIntent, GALLERY_REQUEST);
    
        MediaController mediaController = new MediaController(this);
        mediaController.setAnchorView(mVideo);
        //mVideo is the VideoView where I insert the video
        mVideo.setMediaController(mediaController);
        mVideo.pause();
    }
    
    
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    
        switch (requestCode) {
            case 1:
                if (resultCode == RESULT_OK) {
                    mVideoUri = data.getData();
                    mVideo.setVideoURI(mVideoUri);
                    mVideo.start();
                }
        }
    }
    

提交回复
热议问题