Wait Until Current Media Finish Playing Before It Play Another In Android
Here is my media player code in android. My problem is the loop plays all the files from the zipfolder without waiting for the current to finish playing. How do I solve this proble
Solution 1:
It's because you're creating a new mp instance for each song. Firstly, you should create a Song class to hold the song information. Alternately, you can just create a list of Strings containing the filepaths to the songs. Then, you can do something like this:
int playlistPos = 0;
protectedvoidonCreate(Bundled savedInstanceState) {
super.onCreate(savedInstanceState);
initSong(songs.get(playlistPos);
mp.start();
mp.setOnCompletionListener(new OnCompletionListener() {
playlistPos++;
initSong(songs.get(playlistPos);
mp.start();
});
}
privatevoidinitSong(Song song) {
// Set the datasource in here, prepare, etc
}
Once each song finishes, it will move the playlistPos along by one, and start the player again.
Post a Comment for "Wait Until Current Media Finish Playing Before It Play Another In Android"