Okay, this is basically how I did it:
First, I made a Playlist called "All Music" and added all my music to it.
Note that this playlist must be sorted by artist.
The next thing to do is to play that playlist so it is loaded into the 'CurrentSongList'.
After that I ran the following code:
Code: Select all
{
int i;
int j = 0;
var Playlist = SDB.PlaylistByTitle["All Music"];
Playlist.CreateChildPlaylist(SDB.PlaylistByTitle["All Music"].Tracks.Artists.Item[0].Name.ToString());
for (i = 0; i < (SDB.Player.CurrentSongList.Count - 1); i++)
{
var Song = SDB.Player.CurrentSongList.Item[i];
var Artist = SDB.Player.CurrentSongList.Item[i].Artist.Name;
var NextArtist = SDB.Player.CurrentSongList.Item[i + 1].Artist.Name;
if (Artist.Contains("The "))
{
Artist = Artist.Replace("The ", "");
}
if (NextArtist.Contains("The "))
{
NextArtist = NextArtist.Replace("The ", "");
}
if (Song != null)
{
Playlist.ChildPlaylists.Item[j].AddTrack(Song);
}
if (!(Artist.Equals(NextArtist)))
{
Playlist.CreateChildPlaylist(NextArtist);
j++;
}
}
Playlist.ChildPlaylists.Item[j].AddTrack(SDB.Player.CurrentSongList.Item[SDB.Player.CurrentSongList.Count]);
}
What this basically does is that it makes a Childplaylist for every Artist in the Playlist "All Music" and puts all songs of that artist in it.
This process may take some time, depending on the number of songs you have.
Now I can just run the next code:
Code: Select all
{
var SongList = new SDBSongList();
SongList = SDB.PlaylistByTitle[txt_Artist.Text.ToString()].Tracks;
SDB.Player.PlaylistClear();
SDB.Player.PlaylistAddTracks(SongList);
SDB.Player.CurrentSongIndex = 0;
}
So you can just type the name of the artist in the txt_Artist TextBox and the player will start playing the playlist with the name of that artist.
There probably are lots of other ways of doing this, but for me this works good enough.
Notes:
- Don't forget to add the MediaMonkey Library COM Reference to your project.
- Don't forget to insert "using SongsDB;" to the top of your .cs file.
- Don't forget to insert
Code: Select all
SongsDB.SDBApplication SDB = new SongsDB.SDBApplication();
SDB.ShutdownAfterDisconnect = false;
in your .cs file.