I have working on to one android application.Normal concept of this application is to Play Song in Multiple Device at Same Time.Everything is done but Song is not play in Sync.I have done lot's of R&d to solve this problem but not getting success.but at end I have found one Issue of Android Media Player.For finding this issue I have making one demo Application.Description is follow.
Demo App Description
I create a two object of Android media player firstPlayer and secondPlayer.firstPlayer Song playing will be start once App is Lunch.now i have taking one Button in test.xml.once the User will click in this button secondPlayer is start and play same music which I set in firstPlayer.and I also Seek secondPlayer at Position where firstPlayer is Play.
Code
changePlayer = (Button) findViewById(R.id.changePlayer);
String fileName = "/qq.mp3";
String baseDir = Environment.getExternalStorageDirectory() + "/Test App" + fileName;
Log.e(TAG, "path :" + baseDir);
try {
firstPlayer = new MediaPlayer();
secondPlayer = new MediaPlayer();
firstPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
secondPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
firstPlayer.setDataSource(baseDir);
secondPlayer.setDataSource(baseDir);
firstPlayer.prepare();
secondPlayer.prepare();
firstPlayer.start();
} catch (IOException e) {
e.printStackTrace();
}
changePlayer.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (!secondPlayer.isPlaying()) {
Log.e(TAG, "Media Player Start M2");
secondPlayer.start();
}
int sek = firstPlayer.getCurrentPosition();
secondPlayer.seekTo(firstPlayer.getCurrentPosition());
//firstPlayer.seekTo(sek);
Log.e(TAG, "Current Playe Time ::" + secondPlayer.getCurrentPosition());
Log.e(TAG, "First Playe Time ::" + sek);
Log.e(TAG, "firstPlayer Playe Time ::" + firstPlayer.getCurrentPosition());
Log.e(TAG, "secondPlayer Playe Time ::" + secondPlayer.getCurrentPosition());
}
});
Problem
- I am getting one Strange problem both media player not play in Sync it's having little bit different for play song.if I seek secondPlayer where firstPlayer is play then it's playing in Sync but it's not happend both player playing different.
Note
- I also try to Solve this Issue using any third party Media player but i didn't get luck.I have implement ExoPlayer,VlcPlayer,UniversalPlayer to solve this problem but It's also having same problem.
Requirement.
- I want to play song in Sync in Two different object of MediaPlayer.
- Did anyone know about any powerful media player which is not having this delay issue.
I hardly Try to solve this Sync issue but i Didn't get Luck.I want 100% Sync in My Application.Just Like Seedio app in IOS.I also test this in IOS but in IOS it's Working fine Both Player play song with 100% sync.
Please Help me if Anyone have any Idea.
I hope you all are clear with my problem.
Thank You
来源:https://stackoverflow.com/questions/35171545/two-object-of-media-player-not-play-song-in-sync-at-same-time