Skip to content

Commit bc384b8

Browse files
committed
Merge pull request #49 from JimmyAppelt/master
Added GetAlbumArtAsByteArrayAsync and GetAlbumArtAsByteArray, Closes #47
2 parents 5c3c354 + 2006486 commit bc384b8

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

SpotifyAPI/Local/Models/Track.cs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ public String GetAlbumArtUrl(AlbumArtSize size)
7575
}
7676
return "";
7777
}
78+
7879
/// <summary>
7980
/// Returns a Bitmap of the album cover in the provided size asynchronous
8081
/// </summary>
@@ -95,6 +96,24 @@ public async Task<Bitmap> GetAlbumArtAsync(AlbumArtSize size)
9596
}
9697
}
9798
}
99+
100+
/// <summary>
101+
/// Returns a byte[] of the the album cover in the provided size asynchronous
102+
/// </summary>
103+
/// <param name="size">AlbumArtSize (160,320,640)</param>
104+
/// <returns>A byte[], which is the albumart in binary data</returns>
105+
public async Task<byte[]> GetAlbumArtAsByteArrayAsync(AlbumArtSize size)
106+
{
107+
using (WebClient wc = new WebClient())
108+
{
109+
wc.Proxy = null;
110+
String url = GetAlbumArtUrl(size);
111+
if (url == "")
112+
return null;
113+
return await wc.DownloadDataTaskAsync(url);
114+
}
115+
}
116+
98117
/// <summary>
99118
/// Returns a Bitmap of the album cover in the provided size
100119
/// </summary>
@@ -115,5 +134,22 @@ public Bitmap GetAlbumArt(AlbumArtSize size)
115134
}
116135
}
117136
}
137+
138+
/// <summary>
139+
/// Returns a byte[] of the album cover in the provided size
140+
/// </summary>
141+
/// <param name="size">AlbumArtSize (160,320,640)</param>
142+
/// <returns>A byte[], which is the albumart in binary data</returns>
143+
public byte[] GetAlbumArtAsByteArray(AlbumArtSize size)
144+
{
145+
using (WebClient wc = new WebClient())
146+
{
147+
wc.Proxy = null;
148+
String url = GetAlbumArtUrl(size);
149+
if (url == "")
150+
return null;
151+
return wc.DownloadData(url);
152+
}
153+
}
118154
}
119155
}

0 commit comments

Comments
 (0)