VideoView - MediaController没有显示

时间:2014-04-10 13:04:30

标签: android android-videoview mediacontroller

我无法让它发挥作用......每当我触摸我的视频时,一切都没有了......虽然,我认为MediaController应该是可见的......

我目前使用以下功能播放视频:

private void playCachedVideo(final VideoView videoView, final Context c, File f)
{
    //videoView.setZOrderOnTop(true);        
    videoView.setOnPreparedListener(new OnPreparedListener()
    {
        @Override
        public void onPrepared(MediaPlayer mp) 
        {
            mp.setOnVideoSizeChangedListener(new OnVideoSizeChangedListener() 
            { 
                @Override
                public void onVideoSizeChanged(MediaPlayer mp, int width, int height) 
                {
                    MediaController mediaController = new MediaController(c);
                    mediaController.setMediaPlayer(videoView);
                    mediaController.setAnchorView(videoView);
                    videoView.setMediaController(mediaController);
                }
            });
        }
    });
    videoView.setVideoURI(Uri.fromFile(f));
    videoView.start();
}

视频播放正常,但我无法显示任何MediaController ......

PS:我在DialogFragment

中展示了玩家

2 个答案:

答案 0 :(得分:0)

试试这个:

mMediaController = new MediaController(getActivity());

c替换为getActivity()

答案 1 :(得分:0)

您需要将控制器连接到VideoView,然后在onPrepared()回调中调用mediaController.show(timeInMillisec)。 这将显示控制器触摸视频,并在指定的timeInMillisec后隐藏控制器。

public class VideoViewActivity extends Activity implements  MediaPlayer.OnPreparedListener{

    private VideoView mVideoView = null;
    MediaController mediaController = null;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.videoview_layout);

        mVideoView = (VideoView) findViewById(R.id.VideoView);
        mVideoView.setOnPreparedListener(this);

        mediaController = new MediaController(mVideoView.getContext());
        mediaController.setMediaPlayer(mVideoView);
        mediaController.setAnchorView(mVideoView);
        mVideoView.setMediaController(mediaController);
        mVideoView.setVideoPath("URL");
    }

    @Override
    public void onPrepared(MediaPlayer mp) {
        mVideoView.start();
        mediaController.show(2000);
    }
}