Archive

Posts Tagged ‘Play song’

Playing a song from library – WP8

Here is the logic to play a particular song from library.

Logic is to loop through all the songs in Media Library and if the song name matches to our song play the song.

string favoriteSong = “mySong.mp3”;

using (Microsoft.Xna.Framework.Media.MediaLibrary library = new Microsoft.Xna.Framework.Media.MediaLibrary())            {

foreach (var song in library.Songs)                {

if (song.Name == favoriteSong) {

FrameworkDispatcher.Update();

// Play the song

Microsoft.Xna.Framework.Media.MediaPlayer.Play(song);

break;

}

}

library.Dispose();

}

🙂