Query Items into songlist

This forum is for questions / discussions regarding development of addons / tweaks for MediaMonkey for Windows 4.

Moderators: Gurus, Addon Administrators

Flaming-Ninja
Posts: 8
Joined: Fri May 10, 2013 5:58 am

Query Items into songlist

Post by Flaming-Ninja »

Hello there,

I'm trying to make a program in Visual C# that will play music with a specific condition.
At first I'll show you some code I already have.
I think That'll explain what I want alot more than trying to explain it all.

Code: Select all

        {
            SongsDB.SDBApplication SDB = new SongsDB.SDBApplication();
            SDB.ShutdownAfterDisconnect = false;
            
            // As an example I use the condition that the Artists has to be Linkin Park
            var Query = "Artist='Linkin Park'";

            // Get all songs by the artist "Linkin Park"
            var QueryData = SDB.Database.QuerySongs(Query);

            // Create a Songlist to add the songs to
            var SongList = new SDBSongList();

            while (true)
            {
                // If EOF, we've seen all the songs by 'Linkin Park', so break out of the loop
                if (QueryData.EOF)
                {
                    break;
                }
                else
                {
                    // Add this song to the SongList
                    SongList.Add(QueryData.Item);
                }
                QueryData.Next();
            }

            // Close the connection to the database
            SDB = null;
            
        }
What I thought this would do is that it would add all the songs by Linkin Park to the Songlist I defined.
But when I try to run this code, the program will fail on

Code: Select all

SongList.Add(QueryData.Item);
I don't see why it does, because if I read it right the QueryData.Item returns me a SDBSongData (http://www.mediamonkey.com/wiki/index.p ... ator::Item)
And the SongList.Add() requires a SDBSongData (http://www.mediamonkey.com/wiki/index.p ... gList::Add)

If I'm right the QueryData (SDB.Database.QuerySongs) returns a SDBSongIterator object, which can handle an 'EOF', an 'Item' and a 'Next' (http://www.mediamonkey.com/wiki/index.p ... ngIterator)
As you can see in my code the 'EOF' Property Get and the 'Next' method do work, but the 'Item' Property get keeps giving me an error.

If anybody could please help me and tell me what I'm doing wrong over here I'd really appreciate that.
Thanks in advance for the trouble to be taken.
Flaming-Ninja
Posts: 8
Joined: Fri May 10, 2013 5:58 am

Re: Query Items into songlist

Post by Flaming-Ninja »

Just to let you guys know, I've finally figured it out myself.
Turned out to be quite a stupid mistake...
I wanted to use a SDBSongData as a SDBListData
So I used a SDB.Player.PlaylistAddTrack(QueryData.Item) method.
Everything is working perfect now!

I'll share my code with you for if there are other with the same problem.

Code: Select all

        private void MediaMonkey()
        {
            SongsDB.SDBApplication SDB = new SongsDB.SDBApplication();
            SDB.ShutdownAfterDisconnect = false;

            string SongTitle = "";
            string Artist = "";
            string Album = "";
            string Genre = "";

            string Query = "SongTitle LIKE '%" + SongTitle + "%' AND Artist LIKE '%" + Artist + "%' AND Album LIKE '%" + Album + "%' AND Genre LIKE '%" + Genre +"%'";
            
            if (SongTitle == "")
                Query = Query.Remove(Query.IndexOf("SongTitle"), 20);
            if (Artist == "")
                Query = Query.Remove((Query.IndexOf("Artist")-4), 21);
            if (Album == "")
                Query = Query.Remove((Query.IndexOf("Album")-4), 20);
            if (Genre == "")
                Query = Query.Remove((Query.IndexOf("Genre")-4), 19);

            var QueryData = SDB.Database.QuerySongs(Query);

            SDB.Player.PlaylistClear();

            while (true)
            {
                if (QueryData.EOF)
                    break;

                else
                {
                    SDB.Player.PlaylistAddTrack(QueryData.Item);
                }

                QueryData.Next();
            }

            SDB.Player.Next();

            SDB = null;
        }
Here you can enter a Title, an Artist, an Album or a Genre or even multiple conditions
MediaMonkey will then add all songs fit to the conditions in the NowPlaying list and start playing it.
Post Reply