I have a simple Android media player that can play multiple videos simultaneously on a single screen. So basically a single media player screen is divided into 4 parts, with 4 mediaPlayer
instance glued together, and each part plays a given video.
It works almost OK when my video files are stored locally on the device. There are synchronization problems, but minor. But when I input a URL for HTTP streaming, there is significant synchronization problems. What is the problem? Generally, how can I remove the synchronization problems?
The only thing I could do was first instantiate the mediaplayers and prepare()
them, then call start()
one after the other so at least the start times be close to eachother. It doesn't have much effect though.
Here I have a method that return each of the mediaplayer
instances:
MediaPlayer mediaPreparation(String filename, boolean setMute) {
String url = "myURL"; // your URL here
// create mediaplayer instance
MediaPlayer mediaPlayer = new MediaPlayer();
if (setMute) {
mediaPlayer.setVolume(0, 0);
}
try {
mediaPlayer.setDataSource(url);
mediaPlayer.prepare();
} catch (IOException e) {
}
mediaPlayer.setLooping(true);
// mediaPlayer.start();
return mediaPlayer;
}
And then I start them one by one:
mp[0].start();
mp[1].start();
mp[2].start();
mp[3].start();