我需要创建Activity,它将播放来自URL的视频。 现在,我使用VideoView和MediaController,当这个活动创建时,在缓冲视频之后它应该播放。它有效,但只播放一次,在媒体控制器正常工作但不播放视频之后。
这是一段代码:
private ProgressDialog progressDialog;
private VideoView videoView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_video);
progressDialog = new ProgressDialog(this);
progressDialog.setTitle("Some title");
progressDialog.setMessage("Buffering...");
progressDialog.setIndeterminate(false);
progressDialog.setCancelable(false);
progressDialog.show();
videoView = (VideoView) findViewById(R.id.video_view);
Intent intent = getIntent();
String url = intent.getStringExtra("extra_url");
Uri uri = Uri.parse(url);
videoView.setVideoURI(uri, HeadersMap); // Here I put my headers - I need to do that.
MediaController mediaController = new MediaController(this);
mediaController.setAnchorView(videoView);
videoView.setMediaController(mediaController);
videoView.requestFocus();
videoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mp) {
progressDialog.dismiss();
videoView.start();
}
});
}
那么,问题是什么?为什么视频无法重复播放?我将光标设置为在控制器上启动,但没有任何反应。我该怎么办呢?或者我该怎么做?
感谢您的回答!
答案 0 :(得分:1)
试试这个,
videoView.setOnPreparedListener(new OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mp) {
mp.setLooping(true);
}
});
您也可以使用setOnCompletionListener
videoView.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mp) {
videoView.start();
}
});
或强>
videoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer arg0) {
mVideoView.start();
}
});
videoView.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
public void onCompletion(MediaPlayer mp) {
mp.reset();
videoView.setVideoURI(uri, HeadersMap);
}
});