In the music player, the playback mode is usually placed in the music after the automatic recognition, the following gives the logical code, you can add appropriate code as needed
public static final int all = 0;//full loop
public static final int singles = 1;//single loop
public static final int RANDOM = 2;//random
After a song is finished (set playback mode here)
public class Completed implements Oncompletionlistener
{
@Override
public void Oncompletion (MediaPlayer MP)
{
if (PlayMode = ALL)//All Loops
{
if (position = = Listmusic.size ()-1)//default loop playback
{
Position = 0;//First
}
Else
{
position++;
}
}
else if (PlayMode = singles)/single loop
{
Position do not need to change
}
else if (PlayMode = = RANDOM)//random
{
Position = (int) (Math.random () *listmusic.size ());//Random playback
}
Elseset ()//other playback processing
}
}
When making a single loop, it is best not to be like the code on the design, because there is no actual position, the program may jump out of a bug, or even crash, I realized that the single loop is listening to the user's mode of choice, when the music playback finished, restart the MediaPlayer on it