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 single = 1;//singles loop public
static final int RANDOM = 2;//random
//A song after playback is complete (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 play
{
position = 0;// First
}
else
{
position++;
}
}
else if (PlayMode = = single)//singles loop
{
//position do not need to change
}
else if (PlayMode = = RANDOM)//random
{
position = (int) (Math.random () *listmusic.size ());//Random play
}
Elseset ()//other playback processing
}
}
Note: When making a single cycle, it is best not to like the code on the design, because there is no actual position, the program may jump out of the 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.