I am trying to develop an Android application that plays more than one video in one video. When one of them is finished, the second should begin, etc.
My videos are saved in the project source folder to get my file names that I make:
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 path to my video image
videoUri = Uri.parse("android.resource://" + getActivity().getPackageName() + "/" + videoNames.get(0)); myVideoView.setVideoURI(videoUri);
to play the rest
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++; } } });
BUT...
every time I try to use this code in a real device, I get the same error “cannot play video” when the first video is completed ...
all videos are .mp4 files recorded with the same device that I use for development ...
any ideas? or other ways to play more videos in sequence? I was looking for a solution everywhere, but I could not find it.
EDIT
DID THIS!! ok .. the mistake was so stupid. Thanks to everyone for the helpful answers.
the error was in the path I was looking for ("these are not the paths you are looking for" cit.)
as I wrote, videos are stored in a raw folder. I used
videoUri = Uri.parse("android.resource://" + MainActivity.ctx.getPackageName() + "/ + videoNames.get(VideoI));
add source folder to path
videoUri = Uri.parse("android.resource://" + MainActivity.ctx.getPackageName() + "/raw/" + videoNames.get(VideoI));
he finally worked .. as I wrote .. it was stupid ..