减少videoview中视频的初始加载时间

时间:2018-10-23 10:56:20

标签: android video android-videoview android-video-player

在我的项目中,我实现了用于视频流的videoview。与其他播放器或浏览器相比,视频观看要花费更少的时间,因此加载和缓冲视频需要花费大量时间。.我在互联网上搜索了几天,却找不到适合我的情况的合适解决方案。我正在从Amazon S3存储桶加载视频,我不认为这是因为服务器

    private void playVideo() {

    vidUri = Uri.parse(movieUrl);

    vidControl = new CustomMediaControl(this, new CustomMediaControl.MediaFullScreen() {
        @Override
        public void fullScreenButtonClicked() {
            setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
        }

        @Override
        public void fullScreenButtonExited() {
            setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
        }
    });

    videoPlayer.setMediaController(vidControl);

    videoPlayer.setVideoURI(vidUri);

    videoPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
        @Override
        public void onPrepared(MediaPlayer mp) {
            // TODO Auto-generated method stub
            mp.start();
            mp.setOnInfoListener(new MediaPlayer.OnInfoListener() {
                @Override
                public boolean onInfo(MediaPlayer mp, int what, int extra) {
                    switch (what) {
                        case MediaPlayer.MEDIA_INFO_VIDEO_RENDERING_START: {
                            progressBar.setVisibility(View.GONE);
                            return true;
                        }
                        case MediaPlayer.MEDIA_INFO_BUFFERING_START: {
                            progressBar.setVisibility(View.VISIBLE);
                            return true;
                        }
                        case MediaPlayer.MEDIA_INFO_BUFFERING_END: {
                            progressBar.setVisibility(View.GONE);
                            return true;
                        }
                    }
                    return false;
                }
            });
        }
    });
    videoPlayer.setOnErrorListener(new MediaPlayer.OnErrorListener() {
        @Override
        public boolean onError(MediaPlayer mp, int what, int extra) {
            Log.e("Media Details", "hello");
            return true;
        }
    });

    videoPlayer.start();
    videoPlayer.seekTo(stopPosition);

}

我还查看了以下链接Link1Link2让我知道您是否需要更多说明

0 个答案:

没有答案