假装sdcard或内部存储器中有5个视频. 现在我已经有了文件路径,我的问题是如何在VIDEO VIEW中插入多个视频?
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 ?
下一个或上一个按钮不起作用
这是我的代码
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); }此代码在单个视频中工作如果我有5个视频怎么办?
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 } }); }我需要这个,因为我将使用MediaController并按下下一个视频
推荐答案在第一个视频停止播放后,您可以使用计数器并增加其值.这可以通过使用MediaPlayer.OnCompletionListener来实现.
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.
以下为我工作:
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.
更多推荐
VideoView添加多个视频并播放
发布评论