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();
}
🙂

![[Step by Step] Beginner : Create a PCF control and add it to a custom page](https://rajeevpentyala.com/wp-content/uploads/2024/12/image-49.png)

Leave a comment