如何在 Android 应用中自动启动多个视频(离线)
How start multiple video automatically in Android app (offline)
早上好,我创建了一个 activity 和一个 videoview 自动启动并以循环模式从 uri 加载视频。
如何在循环模式下加载 2 个或三个视频?
例如从 Uri(xxx1, xxx2, xxx3) 加载?
提前致谢
我认为您可以创建 RecyclerView 或 ListView 或 ScrollView 以及相应的适配器或子视频视图。
Uri[] 或 ArrayList
中有视频 Uris 列表
在各自的 getView 或 for(Uri uri : mUris) 循环中调用这些
这里是播放视频的单例
private void playVideo(Uri uri) {
//set the media controller buttons
if (mediaControls == null) {
mediaControls = new MediaController(AndroidVideoViewExample.this);
}
//initialize the VideoView
myVideoView = (VideoView) findViewById(R.id.video_view);
try {
//set the media controller in the VideoView
myVideoView.setMediaController(mediaControls);
//set the uri of the video to be played
myVideoView.setVideoURI(uri);
} catch (Exception e) {
Log.e("Error", e.getMessage());
e.printStackTrace();
}
//we also set an setOnPreparedListener in order to know when the video file is ready for playback
myVideoView.setOnPreparedListener(new OnPreparedListener() {
public void onPrepared(MediaPlayer mediaPlayer) {
// close the progress bar and play the video
progressDialog.dismiss();
//if we have a position on savedInstanceState, the video playback should start from here
myVideoView.seekTo(position);
if (position == 0) {
myVideoView.start();
} else {
//if we come from a resumed activity, video playback will be paused
myVideoView.pause();
}
}
});
}
早上好,我创建了一个 activity 和一个 videoview 自动启动并以循环模式从 uri 加载视频。 如何在循环模式下加载 2 个或三个视频? 例如从 Uri(xxx1, xxx2, xxx3) 加载? 提前致谢
我认为您可以创建 RecyclerView 或 ListView 或 ScrollView 以及相应的适配器或子视频视图。
Uri[] 或 ArrayList
中有视频 Uris 列表在各自的 getView 或 for(Uri uri : mUris) 循环中调用这些
这里是播放视频的单例
private void playVideo(Uri uri) {
//set the media controller buttons
if (mediaControls == null) {
mediaControls = new MediaController(AndroidVideoViewExample.this);
}
//initialize the VideoView
myVideoView = (VideoView) findViewById(R.id.video_view);
try {
//set the media controller in the VideoView
myVideoView.setMediaController(mediaControls);
//set the uri of the video to be played
myVideoView.setVideoURI(uri);
} catch (Exception e) {
Log.e("Error", e.getMessage());
e.printStackTrace();
}
//we also set an setOnPreparedListener in order to know when the video file is ready for playback
myVideoView.setOnPreparedListener(new OnPreparedListener() {
public void onPrepared(MediaPlayer mediaPlayer) {
// close the progress bar and play the video
progressDialog.dismiss();
//if we have a position on savedInstanceState, the video playback should start from here
myVideoView.seekTo(position);
if (position == 0) {
myVideoView.start();
} else {
//if we come from a resumed activity, video playback will be paused
myVideoView.pause();
}
}
});
}