VideoView添加多个视频并播放

编程入门 行业动态 更新时间:2024-10-10 01:20:54
本文介绍了VideoView添加多个视频并播放的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

假装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添加多个视频并播放

本文发布于:2023-11-27 18:50:47,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1639192.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:多个   视频   VideoView

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!