Ejemplo n.º 1
0
 private byte[] GetAlbumArtBuffer(int timeout = 2, libspotify.sp_image_size size = libspotify.sp_image_size.SP_IMAGE_SIZE_SMALL)
 {
     if (string.IsNullOrEmpty(artlink))
     {
         artlink = GetAlbumArtLink(size);
     }
     return(Spotify.GetAlbumArt(artlink, timeout));
 }
Ejemplo n.º 2
0
        private async Task <System.Drawing.Image> GetAlbumArtAsync()
        {
            if (_artwork != null)
            {
                return(_artwork);
            }

            try
            {
                int timeout = 1;
                int tries   = 0;
                while (_artwork == null)
                {
                    libspotify.sp_image_size size = libspotify.sp_image_size.SP_IMAGE_SIZE_SMALL;
                    if (timeout < 30)
                    {
                        timeout = timeout * 2;
                    }
                    else
                    {
                        tries++;
                        if (tries % 3 == 0)
                        {
                            size = libspotify.sp_image_size.SP_IMAGE_SIZE_SMALL;
                        }
                        else if (tries % 3 == 1)
                        {
                            size = libspotify.sp_image_size.SP_IMAGE_SIZE_NORMAL;
                        }
                        else if (tries % 3 == 2)
                        {
                            size = libspotify.sp_image_size.SP_IMAGE_SIZE_LARGE;
                        }
                    }
                    var buffer = GetAlbumArtBuffer(timeout, size);
                    if (buffer != null)
                    {
                        _artwork = System.Drawing.Image.FromStream(new MemoryStream(buffer));
                    }
                    if (_artwork == null)
                    {
                        await Task.Delay(250);
                    }
                }
                RaisePropertyChanged("AlbumArt");
                return(_artwork);
            }
            catch (Exception e)
            {
                LogTo.ErrorException("Album art error", e);
                return(null);
            }
        }
Ejemplo n.º 3
0
        private string GetAlbumArtLink(libspotify.sp_image_size artSize = libspotify.sp_image_size.SP_IMAGE_SIZE_SMALL)
        {
            var image = Spotify.GetAlbumArtLink(_albumPtr, artSize);

            if (image == null)
            {
                image = Spotify.GetAlbumArtLink(_albumPtr, libspotify.sp_image_size.SP_IMAGE_SIZE_SMALL);
            }
            if (image == null)
            {
                image = Spotify.GetAlbumArtLink(_albumPtr, libspotify.sp_image_size.SP_IMAGE_SIZE_NORMAL);
            }
            if (image == null)
            {
                image = Spotify.GetAlbumArtLink(_albumPtr, libspotify.sp_image_size.SP_IMAGE_SIZE_LARGE);
            }
            if (image == null)
            {
                throw new Exception("Couldn't get art link");
            }
            return(image);
        }
Ejemplo n.º 4
0
        public static string GetAlbumArtLink(IntPtr albumPtr, libspotify.sp_image_size size)
        {
            IntPtr linkPtr = libspotify.sp_link_create_from_album_cover(albumPtr, size);

            if (linkPtr == IntPtr.Zero)
            {
                Log.Warning(Plugin.LOG_MODULE, "No link could be created for album cover");
                return(null);
            }
            try
            {
                var s = Functions.LinkPtrToString(linkPtr);
                //Log.Debug(Plugin.LOG_MODULE, "<< Album.GetAlbumArtLink() link={0}", s);
                return(s);
            }
            finally
            {
                if (linkPtr != IntPtr.Zero)
                {
                    libspotify.sp_link_release(linkPtr);
                }
            }
        }