Loading Album Art into C# pictureBox

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

Moderator: Gurus

cooledspirit
Posts: 8
Joined: Tue Oct 13, 2009 5:47 am

Loading Album Art into C# pictureBox

Post by cooledspirit » Fri Oct 16, 2009 7:46 am

Hi,

does anybody have sample code that shows me how to load Album Art of any list into a C# pictureBox ?
I'm having trouble converting the SDBImage to the pictureBox... :-?

In case no code in C# is available, VB will do too...

Kind regards,

Cooled Spirit

Peke
Posts: 12500
Joined: Tue Jun 10, 2003 7:21 pm
Location: Serbia
Contact:

Re: Loading Album Art into C# pictureBox

Post by Peke » Fri Oct 16, 2009 6:35 pm

Have you checked Trixmoto Album art tagger?
Best regards,
Pavle
MediaMonkey Team lead QA/Tech Support guru
Admin of Free MediaMonkey addon Site HappyMonkeying
Image
Image
How to add SCREENSHOTS to forum

cooledspirit
Posts: 8
Joined: Tue Oct 13, 2009 5:47 am

Re: Loading Album Art into C# pictureBox

Post by cooledspirit » Sat Oct 17, 2009 12:46 pm

Hi,

thanks for the info, but I want to access the album art from outside MM, in a .NET environment. Intention is to later on, if I ever get there, work totally remotely via webinterface or so.

So any hint or help on how to load albumart in .NET environment, preferably C#, but VB .NET is also welcome, is highly appreciated. :D

Kind regards,

David.

Peke
Posts: 12500
Joined: Tue Jun 10, 2003 7:21 pm
Location: Serbia
Contact:

Re: Loading Album Art into C# pictureBox

Post by Peke » Sat Oct 17, 2009 8:17 pm

That script should give you enough info how to access and extract Image to temp location for external use. I would suggest you to look at that script (I doubt that Trixmoto will mind if you ask him to use his code as starting point) and then give us some sample code to debug. It will take us less time and will be able to help you more directly. Also Check this http://www.mediamonkey.com/wiki/index.p ... _scripting to see how to access Main Automatization object from various coding langs including C#.

EDIT: To start with try to use SDB.Player.CurentSong.AlbumArt and manipulate result using API described for AlbumArtList Item by Item. Just let us see what you are trying to do in example.

I successfully saved all Album arts into Files using this method and using MM internal FileSystem Object along with WriteData.

Note: Each link is for relative api description.
Best regards,
Pavle
MediaMonkey Team lead QA/Tech Support guru
Admin of Free MediaMonkey addon Site HappyMonkeying
Image
Image
How to add SCREENSHOTS to forum

botijo
Posts: 415
Joined: Fri Dec 07, 2007 3:20 am
Location: Ireland

Re: Loading Album Art into C# pictureBox

Post by botijo » Mon Dec 07, 2009 4:15 pm

Hi, there,
I also solved this problem for my UPNP server that is written in C# with .NET (source is in my signature). In the file MMwebserverasync.cs file, lines 491, I wrote:

Code: Select all

            switch (command)
            {
[...]
                case "albumartext":
                    item = item.Split('.')[0];
                    SDBIter = (SDBDBIterator)SDB.Database.OpenSQL("SELECT * FROM Covers WHERE ID=" + item);
                    SDBSongIter = (SDBSongIterator)SDB.Database.QuerySongs("Songs.ID = " + SDBIter.get_StringByName("IDSONG"));
                    String path = SDBSongIter.Item.Path;
                    path = path.Substring(0, path.LastIndexOf('\\') + 1);
                    filename = path + SDBIter.get_StringByName("COVERPATH");
                    MIMEtype = "image/jpeg";
                    break;
                case "albumartemb":
                    item = item.Split('.')[0];
                    SDBIter = (SDBDBIterator)SDB.Database.OpenSQL("SELECT * FROM Covers WHERE ID=" + item);
                    // So from the COVERS pick up the COVERORDER, and hope that this works
                    SDBSongIter = (SongsDB.SDBSongIterator)SDB.Database.QuerySongs("Songs.ID = " + SDBIter.get_StringByName("IDSONG"));
                    SongsDB.SDBImage image = SDBSongIter.Item.AlbumArt.get_Item(Convert.ToInt32(SDBIter.get_ValueByName("COVERORDER"))).Image;
                    // Following switch is unneccesary, just for debug in case something goes wrong
                    switch (image.ImageFormat)
                    {
                        case "image/jpg":
                        case "image/jpeg":
                            filename = SDB.TemporaryFolder + "\\" + item + ".jpg";
                            MIMEtype = "image/jpg";
                            break;
                        case "image/png":
                            filename = SDB.TemporaryFolder + "\\" + item + ".png";
                            MIMEtype = "image/png";
                            break;
                        case "image/gif":
                            filename = SDB.TemporaryFolder + "\\" + item + ".gif";
                            MIMEtype = "image/gif"; 
                            break;
                        default:
                            filename = SDB.TemporaryFolder + "\\" + item + ".jpg";
                            MIMEtype = "image/jpg";
                            break;
                    }
                    if (image.ImageDataLen>0)
                    {
                        filename = SDB.TemporaryFolder + "\\" + item + ".jpg";
                        // Following code has been taken out from the Wiki
                        outputfile = FS.CreateTextFile(filename, true);
                        outputfile.WriteData(image.ImageData, image.ImageDataLen);
                        outputfile.Close();
                        temporaryfile = true;
                    }
[...]
As you can see, my trick here was to use any external Album Art if possible. I figured out that the path in the AlbumArt is related to the song path, that is the reason why I ask for the song information. If it is embedded into the track, what I do is write the file to harddisk. That way I can send a file that is in the harddisk directly to the HTTP client.
UPNP uses HTTP for file transfers, so I created an URL scheme that makes sense: http://<server>/<command>/<item>. In the case of graphs, I added the extension as it makes it easier to debug sometimes with a browser.
I hope you like the method I was using, and if not, please comment on improvements!
Regards.

Post Reply