如何在MediaController加载视频(直播)而不播放时显示进度条?

问题描述 投票:1回答:2

这是我的活动代码:

public class VideoActivity extends FragmentActivity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_video);

        VideoView videoView = (VideoView) findViewById(R.id.activity_video_videoview);
        MediaController mediaController = new MediaController(this);
        mediaController.setAnchorView(videoView);
        Uri video = Uri
                .parse("http://www.ebookfrenzy.com/android_book/movie.mp4");
        videoView.setMediaController(mediaController);
        videoView.setVideoURI(video);
        videoView.start();
    }
}

视频缓存但未播放时我想显示进度条。我该怎么做?

android android-videoview mediacontroller
2个回答
2
投票

设置OnPreparedListener并关闭那里的对话框:

在您的活动中声明进度对话框:

private static ProgressDialog progressDialog;

然后在onCreate方法中:

...
progressDialog = ProgressDialog.show(this, "", "Loading...", true);
videoView.setOnPreparedListener(new OnPreparedListener() {

    public void onPrepared(MediaPlayer arg0) {
        progressDialog.dismiss();
        videoView.start();
    }
});

0
投票

检查新添加的行应该按照您的意图执行。

    public class VideoActivity extends FragmentActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_video);

    VideoView videoView = (VideoView) findViewById(R.id.activity_video_videoview);
    MediaController mediaController = new MediaController(this);
    mediaController.setAnchorView(videoView);
    Uri video = Uri
            .parse("http://www.ebookfrenzy.com/android_book/movie.mp4");
    videoView.setMediaController(mediaController);
    // New Line 
    ProgressDialog pDialog = ProgressDialog.show(this, "", "Loading Video");
    videoView.setVideoURI(video);
    //New Line Added
    pDialog.dismiss
    videoView.start();
}
}
© www.soinside.com 2019 - 2024. All rights reserved.