Play video one after another - android

I need to play two video one after another(as a pair), the first video is as intro video and the second video is as main video, So what I actually need is that after finishing intro video the main video will start...say intro-1 & main-1, intro-2&main-2, intro-3& main3...so on.
the problem that I am getting is that i cnt move to intro video again after completing the main video.Only the main video is played again and again
Here is that code:
videoView.setVideoPath(introPath);
videoView.setMediaController(new MediaController(this));
videoView.requestFocus();
videoView.start();
videoView.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
public void onCompletion(final MediaPlayer mp) {
videoView.setVideoPath(mainPath);
MediaController mc = new MediaController(DisplayVideo.this);
videoView.requestFocus();
videoView.start();
}
}
any help will really be appreciated Thanks

Create a list of the video paths, something like:
List<String> videoPathes = new ArrayList<String>();
videoPathes.add(path1);
videoPathes.add(path2);
// etc..
and some index, for example:
int i = 0;
In the onCompletionListener, set the next path this way:
public void onCompletion(final MediaPlayer mp) {
i = (i + 1) % videoPathes.size();
videoView.setVideoPath(videoPathes.get(i));
// the rest ...
}

Related

android VideoView can't play this video error

I was trying to play a video by streaming it from internet.
videoView = findViewById(R.id.videoView);
bufferProgress = findViewById(R.id.bufferProgress);
videoURL = "https://firebasestorage.googleapis.com/v0/b/sample2-e4836.appspot.com/o/Video%2FFourthVideo.mp4?alt=media&token=6106b76c-be43-4fb6-b29f-64df699bec3d";
Uri uri = Uri.parse(videoURL);
videoView.setVideoURI(uri);
videoView.requestFocus();
bufferProgress.setVisibility(View.VISIBLE);
videoView.start();
videoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
#Override
public void onPrepared(MediaPlayer mediaPlayer) {
mediaPlayer.start();
mediaPlayer.setOnVideoSizeChangedListener(new MediaPlayer.OnVideoSizeChangedListener() {
#Override
public void onVideoSizeChanged(MediaPlayer mediaPlayer, int i, int i1) {
bufferProgress.setVisibility(View.INVISIBLE);
mediaPlayer.start();
}
});
}
});
this code I'm using right now in my onCreate.
At first it was working good.
But then I just changed my videoURL with diffrent link.
& since then I'm getting this error, not just for one I tried many different links but the problem was same.
But for first link again there is no problem for playing video.
after that I revoked those links of videos. and now I'm getting an error that Unfortunately this app has stopped!
note:
other activities of my app works fine.
try any links as your wish.

FFMpeg add text to actual video file after recording in Android

Am recording a video in Android device using JavaCV and playing it using a videoview. Now want to show a text on video while playing, which is entered after recording video. This text must be seen in all video players while playing the video.
I have gone thro the link How to add text on video recording? too which is expected here too
This is the method called after the video is recorded.
private void playRecordedVideo(Uri videoUri, boolean playVideoInLoop)
{
RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
layoutParams.addRule(RelativeLayout.CENTER_IN_PARENT, RelativeLayout.TRUE);
videoView.setLayoutParams(layoutParams);
videoView.setVisibility(View.VISIBLE);
videoView.setVideoURI(videoUri);
if(playVideoInLoop)
{
MediaController mediaController = new MediaController(MainActivity.this);
mediaController.setAnchorView(videoView);
videoView.setMediaController(mediaController);
videoView.setOnPreparedListener (new OnPreparedListener() {
#Override
public void onPrepared(MediaPlayer mp) {
mp.setLooping(true);
}
});
}
else
{
videoView.setMediaController(null);
}
videoView.start();
btnStart.setText(getString(R.string.txt_finish));
}

multiple videos play one after the another

can anyone teach me how to make videos play one after the other
I need the full code
I have 4 videos
Video1, Video2, Video3, Video4
I want Video1 to play first then followed Video2, then followed by Video3, then followed by Video4
String path="android.resource://" + getPackageName() +"/" + R.raw.Video1;
videoView1.setVideoURI(Uri.parse(path));
videoView1.start();
Short & Simple
Let's say you have four videos in array list
ArrayList<String> urlList = new ArrayList<>();
Create one counter variable to manage current video playing.
int video_counter = 0;
Now following code make your work easy to play dynamic range of video to play in loop (like one after another).
VideoView vv_video = findViewById(R.id.vv_video);
vv_video.setVideoURI(Uri.parse(urlList.get(counter_video_loop)));
vv_video.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
#Override
public void onPrepared(MediaPlayer mp) {
vv_video.start();
}
});
vv_video.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
#Override
public void onCompletion(MediaPlayer mp) {
if ((video_counter + 1) <= urlList.size()) {
video_counter++;
vv_video.setVideoURI(Uri.parse(urlList.get(video_counter + 1)));
vv_video.start();
}
}
});
Assume you have a Videoview, you could for example put the paths to the videos into an array, and detect the end of playback like this:
videoView.setOnCompletionListener(new OnCompletionListener() {
#Override
public void onCompletion(MediaPlayer mp) {
//start next video here
//for example, set video path to next array item
}
});
Maybe you should create a new VideoView to play next video at OnCompletionListener, and remove the old VideoView ,add the new VideoView.
It works for me.
use exoPlayer for concatenate multi video

Play video one after another simultaneously smoothly [without visible switching from one to another]

I am new to android and want to play videos one after another simultaneously so that it looks like continuous video.
I have found this link on stackoverflow very helpful. how-to-play-videos-one-after-another-simultaneously
When I am using this then though I am able to play videos one after another,
But switching from one segment to other results in pause the video for a second before playing next one. So It don't looks like continuous videos due to this.
Please help me to resolve my problem.
Here is my Code.
public class VideoActivity extends Activity{
VideoView videoView, videoView1;
MediaController mc;
int count = 0;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_video);
videoView = (VideoView) findViewById(R.id.VVSimpleVideo);
setup();
videoView.setOnCompletionListener(completionListener);
}
public void setup() {
String _path = "/mnt/sdcard/Video/"+count+".mp4";
videoView.setVideoPath(_path);
videoView.start();
count++;
}
private OnCompletionListener completionListener=new OnCompletionListener() {
public void onCompletion(MediaPlayer mp) {
mp.stop();
setup();
}
};
}
Now I have tried to play by taking two instances of VideoView class.
Tried to play the first video by first player and second video by second player,
Third video from first player and fourth video from second player and so on.
But still I am not able to play the video smoothly and the same problem exist.
Here is my code with double player.
public class VideoActivity extends Activity{
VideoView videoView, videoView1;
MediaController mc;
int count = 0;
String _path;
String _path1;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_video);
videoView = (VideoView) findViewById(R.id.VVSimpleVideo);
_path = "/mnt/sdcard/Video/"+count+".mp4";
videoView.setVideoPath(_path);
videoView.start();
//setup();
videoView.setOnCompletionListener(completionListener);
videoView1 = (VideoView) findViewById(R.id.VVSimpleVideo);
videoView1.setOnCompletionListener(completionListener1);
count++;
_path1 = "/mnt/sdcard/Video/"+count+".mp4";
videoView1.setVideoPath(_path1);
}
public void setup() {
videoView.start();
count++;
_path1 = "/mnt/sdcard/Video/"+count+".mp4";
videoView1.setVideoPath(_path1);
}
public void setup1() {
videoView1.start();
count++;
_path = "/mnt/sdcard/Video/"+count+".mp4";
videoView.setVideoPath(_path);
}
private OnCompletionListener completionListener=new OnCompletionListener() {
public void onCompletion(MediaPlayer mp) {
mp.stop();
setup1();
}
};
private OnCompletionListener completionListener1=new OnCompletionListener() {
public void onCompletion(MediaPlayer mp) {
mp.stop();
setup();
}
};
}
You're not really using two VideoViews at all, you're assigning both VideoView and VideoView1 to R.id.VVSimpleVideo, so they are the same object. That means each time you hit onCompletion, it's setting itself up all over again, instead of setting up one and playing the other.
Try creating two separate VideoView objects in your layout. Have one set to VISIBLE and one set to GONE/INVISIBLE, and swap when you want to change.
I can't guarantee it will make it "seamless", though, since that's an almost impossible task. Even most desktop media players aren't truly seamless. It just depends on what tolerance you have for seams.

Mute a playing video by VideoView in Android Application

I want to mute a playing Video by VideoView in my Android Application.
I couldn't find any method to do so in VideoView Class.
Any idea how to do this?
I have found a method "setVolume" in MediaPlayer Class, But I am unable to find any working code to play video by MediaPlayer class.
So I believe I can set volume 0 by this method.
Therefore I am looking for any working code to play video using MediaPlayer Class or how to control volume using VideoView Class.
Below is the code for playing video using VideoView , which I am using.
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_video);
VideoView videoView = (VideoView)this.findViewById(R.id.VVSimpleVideo);
MediaController mc = new MediaController(this);
mc.setAnchorView(videoView);
mc.setMediaPlayer(videoView);
videoView.setMediaController(mc);
String _path = "/mnt/sdcard/Movies/video5.mp4";
videoView.setVideoPath(_path);
videoView.requestFocus();
videoView.start();
}
If you want to get access to the MediaPlayer of a VideoView you have to call MediaPlayer.OnPreparedListener and MediaPlayer.OnCompletionListener, then you can call MediaPlayer.setVolume(0f, 0f); function to set the volume to 0.
Do this:
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_video);
VideoView videoView = (VideoView)this.findViewById(R.id.VVSimpleVideo);
MediaController mc = new MediaController(this);
mc.setAnchorView(videoView);
mc.setMediaPlayer(videoView);
videoView.setMediaController(mc);
String _path = "/mnt/sdcard/Movies/video5.mp4";
videoView.setVideoPath(_path);
videoView.setOnPreparedListener(PreparedListener);
videoView.requestFocus();
//Dont start your video here
//videoView.start();
}
MediaPlayer.OnPreparedListener PreparedListener = new MediaPlayer.OnPreparedListener(){
#Override
public void onPrepared(MediaPlayer m) {
try {
if (m.isPlaying()) {
m.stop();
m.release();
m = new MediaPlayer();
}
m.setVolume(0f, 0f);
m.setLooping(false);
m.start();
} catch (Exception e) {
e.printStackTrace();
}
}
};
videoview.setOnPreparedListener(new OnPreparedListener() {
#Override
public void onPrepared(MediaPlayer mp) {
mp.setVolume(0, 0);
}
});
I have done this using MediaPlayer class.
I have used setVolume function of MediaPlayer class to set the volume to 0.
also I have realised that dont use AudioManager class, because using AudioManager if a set volume to 0, then it set volume to 0 for all the instance of MediaPlayer and VideoView. But if you will use setVolume() method of MediaPlayer then it will just Mute the volume of that instance only.
Also set volume to 0 is bot easy using VideoView because VideoView is a wrapper over MediaPlayer class and just allow to access few function of MediaPlayer.
Also I have read on some blog that though you can reference MediaPlayer instance using VideoView instances, but its very complex and its not recommended to do so.
Hope this would be helpful to other new readers how try to do similar things.

Categories

Resources