How to enable shuffle mode in UWP MediaPlayer

Viewed 111

I am using MediaPlayer with MediaPlaybackList to play mp3 files in my app.

Playlist defined like this:

SongList = new MediaPlaybackList
{
    AutoRepeatEnabled = true,
    ShuffleEnabled = true
};

SongList is populated with 3 songs.

I play music using this code:

private MediaPlayer mPlayerMusic = new MediaPlayer();
mPlayerMusic.Source = SongList;
mPlayerMusic.Play();

Every time this runs, the same song is played! Shuffle does not seem to work. Auto-repeat does work and the first song is played after the last one, but no shuffle!

What am I doing wrong here?

1 Answers

If you want to play mp3 files in shuffle mode, you need to delete the statement ShuffleEnabled=true within the statement SongList= new MediaPlaybackList{…} and add a statement SongList.ShuffleEnabled = true; above the statement mPlayerMusic.Source = SongList;. Like this:

SongList = new MediaPlaybackList()
{
    AutoRepeatEnabled = true
};

SongList is populated with 3 songs.

Play music using this code:

private MediaPlayer mPlayerMusic = new MediaPlayer();

SongList.ShuffleEnabled = true;
mPlayerMusic.Source = SongList;
mPlayerMusic.Play();

Note, try to populate four songs into SongList and the statement ShuffleEnabled=true within the statement SongList= new MediaPlaybackList{…} may work.

Related