我想开发一个videoview扮演多个视频Android应用程序。当一个完成后,第二个有启动等
I'm trying to develop an android application that plays more than one video in one videoview. When one is finished, the second has to start and so on.
我的视频都存储在项目的原始文件夹,得到他们的文件名我做的:
My videos are stored in the raw folder of the project, to get their filenames i do:
Field[] fields = R.raw.class.getFields(); final List<String> videoNames = new ArrayList<String>() ; for(Field field: fields){ videoNames.add(field.getName()); }然后我设定的第一个路径到我的视频查看
then i set the first one's path to my video view
videoUri = Uri.parse("android.resource://" + getActivity().getPackageName() + "/" + videoNames.get(0)); myVideoView.setVideoURI(videoUri);玩别人
myVideoView.setOnCompletionListener(new MediaPlayer.OnCompletionListener() { @Override public void onCompletion(MediaPlayer mp) { videoUri = Uri.parse("android.resource://" + getActivity().getPackageName() + "/" + videoNames.get(VideoI)); myVideoView.setVideoURI(videoUri); myVideoView.start(); if(VideoI==videoNames.size()-1) { VideoI=0; } else{ VideoI++; } } });但是...
每当我尝试在真实设备此code的时候,我得到了同样的错误不能播放视频的时候,第一视频完成...
every time that i try this code in real device, i get the same error "can't play video" when the first video is finished...
所有的视频都记录了,我使用了相同的设备.mp4档案开发...
all the videos are .mp4 file recorded with the same device that i use for develop...
什么想法?或者其他的方式来按顺序播放更多的视频?我找了一个解决方案,但到处都是我无法找到它。
any ideas? or other ways to play more videos in sequence? I looked for a solution everywhere but i couldn't find it..
修改
做到了!确定..错误是如此愚蠢的..谢谢大家了有用的答案。
DID IT!! ok.. the error was so silly.. thank you all for the helpful answers.
错误是在路径我一直在寻找(这些不是你想找的路径CIT)。
the error was in the path i was looking for ("these are not the paths your looking for" cit.)
为我写的,这些视频都存储在文件夹中的原始..我使用
as i wrote, the videos are stored in raw folder.. i was using
videoUri = Uri.parse("android.resource://" + MainActivity.ctx.getPackageName() + "/ + videoNames.get(VideoI));添加原料的文件夹路径
adding raw folder in path
videoUri = Uri.parse("android.resource://" + MainActivity.ctx.getPackageName() + "/raw/" + videoNames.get(VideoI));它最后的工作。至于我写的..这是一个愚蠢的。
it finally worked.. as i wrote.. it was a silly..
推荐答案好吧你得到错误,因为你试图在CH375复位之前重新初始化videoview。更改了您的code这样的。
Well you are getting error because you are trying to initialize videoview again before reseting it. Make a change to your code like this.
myVideoView.setOnCompletionListener(new MediaPlayer.OnCompletionListener() { @Override public void onCompletion(MediaPlayer mp) { startOtherVid(); } });现在进行方法 startOtherVid()和释放previous相继在这里初始化videoview。
Now make method startOtherVid() and initialize videoview here after releasing the previous one.
private void startOtherVid(){ myVideoView.stopPlayback(); videoUri = Uri.parse("android.resource://" + getActivity().getPackageName() + "/" + videoNames.get(VideoI)); myVideoView.setVideoURI(videoUri); myVideoView.start(); .... ..... }此方式,您将释放一个videoview对象并重新创建。会有很短的时间来加载,但你可以直观地处理它。
This way you will release one videoview object and create again. There will be a short time to load, but you can handle it visually.
修改
您还可以释放MediaPlayer对象和解决您的问题。
You can also release mediaplayer object and solve your problem.
public void onCompletion(MediaPlayer mp) { try { mp.reset(); videoUri = Uri.parse("android.resource://" + getActivity().getPackageName() + "/" + videoNames.get(VideoI)); myVideoView.setVideoURI(videoUri); myVideoView.start(); } catch(Exception e){e.printstacktrace();} });干杯。)
更多推荐
Android的VideoView
发布评论