开发者

MediaController setAnchorview spans whole screen

开发者 https://www.devze.com 2023-02-22 20:21 出处:网络
Hey, I\'m trying to fix a bug in a project. They\'ve called into existence a mediacontroller and set its anchor view to be the video view.

Hey, I'm trying to fix a bug in a project. They've called into existence a mediacontroller and set its anchor view to be the video view.

But when i play the video the mediacontroller is drawn across the entire screen and not floating above the video view as the documentation would suggest.

Code:

    MediaController mediaController = new MediaController(mVideoView.getContext());
    mediaControl开发者_运维问答ler.setAnchorView(mVideoView);

    mVideoView.setMediaController(mediaController);

And the XML;

     <VideoView
        android:layout_width="854px"
        android:layout_weight="1"
        android:id="@+id/welcome_video"
        android:layout_height="480px"
        android:layout_gravity="center"
    ></VideoView>

I can't see What is wrong here. Does anybody know how to fix this?


I fixed this issue, it was to do with the LinearLayout the VideoView was inside. It was set to match_parent and not wrap_content.


More detailed answer:

Wrap VideoView with LinearLayout

<LinearLayout
    android:id="@+id/media_layout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true">

    <VideoView
        android:id="@+id/live_video"
        android:layout_width="match_parent"
        android:layout_height="240dp"
         />

</LinearLayout>

just setAnchor() onto the LinearLayout

mediaLayout = (LinearLayout)view.findViewById(R.id.media_layout);
liveVideo = (VideoView) view.findViewById(R.id.device_live_video);
mc = new MediaController(getActivity());
// Here it is
mc.setAnchorView(mediaLayout);

liveVideo.requestFocus();

liveVideo.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {

    @Override
    public void onPrepared(MediaPlayer mp) {
        mp.setOnVideoSizeChangedListener(new MediaPlayer.OnVideoSizeChangedListener() {
            @Override
            public void onVideoSizeChanged(MediaPlayer mp, int width, int height) {
                LogUtils.LOGD(TAG, "Media Player Video Size changed.");
                  /*
                   *  add media controller
                   */
                liveVideo.setMediaController(mc);
                  /*
                   * and set its position on screen
                   */
                //mc.setAnchorView(liveVideo);
            }
        });
    }
});
0

精彩评论

暂无评论...
验证码 换一张
取 消