在我的项目中,我实现了用于视频流的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);
}