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.
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] 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;
}
[...]
[/code]
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.