Closed McBainUK closed 12 years ago
I've just added some some API updates to simplify this in commit dc30b892f9b2013b3dd5a34b359416e6366a3ce0. This enables you to use ISpotifySession.GetImageFromId
(extension-method), and then IImage.GetImage
(also an extension-method). Take a look at the changes is said commit if you are confused, as it should be fairly simple to understand.
Unfortunately I never get an image back for any of my playlists as the format is always SP_IMAGE_FORMAT_UNKNOWN.
Can you help debug?
Try ignoring the image-format and see if that works. If it does, you can comment out the format-checks and push it up, and create a pull-request. Will be good git exercise :). If it does fix the issue, include "fixes #16" in the commit-comment.
Ignoring the image-format just makes it crash on the next line ;) The byte[] data is always null, not sure why.
Do you wait for the image to load?
Tested and working. You simply need to wait for the image to actually load using the extensions IImage.WaitForLoaded
.
I've added this to SpotifireServer.cs:
public System.Drawing.Image GetImage(string id)
{
try
{
var iimage = this.spotify.GetImageFromId(id);
if (iimage != null)
{
iimage.WaitForLoaded();
return iimage.GetImage();
}
}
catch (Exception)
{
}
return null;
}
iimage.GetImage() always fails with an SP_IMAGE_FORMAT_UNKNOWN / null data error. Can you post your test code?
This is the current code I use for testing:
static void spotify_LoginComplete(ISession sender, SessionEventArgs e)
{
var search = spotify.SearchTracks("smile", 0, 1);
Console.WriteLine("Searched");
search.WaitForCompletion();
Console.WriteLine("Search complete");
var track = search.Tracks[0];
spotify.PlayerLoad(track);
spotify.PlayerPlay();
Console.WriteLine("Getting browse");
var browse = track.Album.Browse();
browse.WaitForCompletion();
Console.WriteLine("Browse completed");
Console.WriteLine("{0} copyrights found in album {1}", browse.Copyrights.Count, track.Album.Name);
Console.WriteLine("Getting artist-browse");
var artist = track.Artists[0];
var artistBrowse = artist.Browse();
artistBrowse.WaitForCompletion();
Console.WriteLine("Artistbrowse complete");
Console.WriteLine("Artistbrowse: Artist has {0} tracks", artistBrowse.Tracks.Count);
IImage image = spotify.GetImageFromId(track.Album.CoverId);
image.WaitForLoaded();
image.Save("test.jpg");
}
I've also tested to replace the Save-call with GetImage()
, and that too works, and if you look at the inner workings of the save-call you'll see that Save just calls GetImage().Save()
so if Save works, so does GetImage. I'm sorry that I'm not able to post my entire test-project, but it's a simple project I'm using to testing containing my logininfo and stuff like that, and code I change regularly, that shouldn't be in source control. It's more of a debug-project than a test-project. Let me know if you still can't get it to work. I also tried out your code, and it worked fine, but it's to little to go on, so try running mine, to see if that works. And if it does the problem lies elsewhere (like you giving it the wrong id or something).
How do I use SpotiFire.Server.Playlist.ImageId from a client to get the actual image (useable in .NET)?