问题
Lets pretend that a 5 videos in sdcard or internal storage.
now I already get the file path, my problem is how can i insert a multiple videos in VIDEO VIEW ?
The next or previous button is not functioning
here is my code
public void getFile()
{
urls = getIntent().getStringArrayListExtra("url_videoAll");
keys = getIntent().getStringArrayListExtra("key_videoAll");
for(int i = 0; i<urls.size();i++) {
String FileName = URLUtil.guessFileName(urls.get(0), null, MimeTypeMap.getFileExtensionFromUrl(urls.get(0)));
String yourFilePath = getBaseContext().getFilesDir() + "/" + FileName;
fileList.add(new File(yourFilePath));
}
playallvideo(fileList);
}
in this CODE ARE WORKING IN SINGLE VIDEO how about if i have 5 videos ?
private void playallvideo(final List<File> file)
{
mediaController = new MediaController(this);
video.setMediaController(mediaController);
video.setVideoPath(file.get(0).toString());
video.start();
mediaController.setPrevNextListeners(new View.OnClickListener() {
public void onClick(View v) {
video.setMediaController(mediaController);
video.setVideoPath(file.get(1).toString());
video.requestFocus();
video.start();
// code for next
}
}, new View.OnClickListener() {
public void onClick(View v) {
video.setMediaController(mediaController);
video.setVideoPath(file.get(1).toString());
video.requestFocus();
video.start();
// code for previous
}
});
}
I need this because I will use MediaController and press the next video
回答1:
You can use a counter and increment the value of it as soon as the first video has stopped playing. This can be achieved by using the MediaPlayer.OnCompletionListener
.
Below worked for me:
private static int currentVideo = 0;
private List<String> fileData = new ArrayList<String>();
videoView.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mp) {
if(!(currentPosition < fileData.size())) {
return;
}
Uri nextUri = Uri.parse(fileData.get(currentPosition++));
videoView.setVideoURI(nextUri);
videoView.start();
//to keep looping into the list, reset the counter to 0.
//in case you need to stop playing after the list is completed remove the code.
if(currentPosition == fileData.size()) {
currentPosition = 0;
}
}
});
Though the post is too old to answer, the beginner developers who end up here will get as much help as I did.
来源:https://stackoverflow.com/questions/34173439/videoview-add-a-multiple-videos-and-play