mirror of
https://github.com/Sarsoo/Spotify.NET.git
synced 2024-12-24 15:06:26 +00:00
Fixed rest of awaits.
This commit is contained in:
parent
a67305cb14
commit
80f58df929
@ -103,7 +103,9 @@ namespace SpotifyAPI.Local.Models
|
|||||||
string url = GetAlbumArtUrl(size);
|
string url = GetAlbumArtUrl(size);
|
||||||
if (url == "")
|
if (url == "")
|
||||||
return null;
|
return null;
|
||||||
var data = await wc.DownloadDataTaskAsync(url);
|
var data =
|
||||||
|
|
||||||
|
wc.DownloadDataTaskAsync(url);
|
||||||
using (MemoryStream ms = new MemoryStream(data))
|
using (MemoryStream ms = new MemoryStream(data))
|
||||||
{
|
{
|
||||||
return (Bitmap)Image.FromStream(ms);
|
return (Bitmap)Image.FromStream(ms);
|
||||||
@ -116,7 +118,7 @@ namespace SpotifyAPI.Local.Models
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="size">AlbumArtSize (160,320,640)</param>
|
/// <param name="size">AlbumArtSize (160,320,640)</param>
|
||||||
/// <returns>A byte[], which is the albumart in binary data</returns>
|
/// <returns>A byte[], which is the albumart in binary data</returns>
|
||||||
public async Task<byte[]> GetAlbumArtAsByteArrayAsync(AlbumArtSize size)
|
public Task<byte[]> GetAlbumArtAsByteArrayAsync(AlbumArtSize size)
|
||||||
{
|
{
|
||||||
using (WebClient wc = new WebClient())
|
using (WebClient wc = new WebClient())
|
||||||
{
|
{
|
||||||
@ -124,7 +126,7 @@ namespace SpotifyAPI.Local.Models
|
|||||||
string url = GetAlbumArtUrl(size);
|
string url = GetAlbumArtUrl(size);
|
||||||
if (url == "")
|
if (url == "")
|
||||||
return null;
|
return null;
|
||||||
return await wc.DownloadDataTaskAsync(url);
|
return wc.DownloadDataTaskAsync(url);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,23 +24,23 @@ namespace SpotifyAPI.Local
|
|||||||
|
|
||||||
internal async void SendPauseRequest()
|
internal async void SendPauseRequest()
|
||||||
{
|
{
|
||||||
await QueryAsync("remote/pause.json?pause=true", true, true, -1);
|
await QueryAsync("remote/pause.json?pause=true", true, true, -1).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
internal async void SendPlayRequest()
|
internal async void SendPlayRequest()
|
||||||
{
|
{
|
||||||
await QueryAsync("remote/pause.json?pause=false", true, true, -1);
|
await QueryAsync("remote/pause.json?pause=false", true, true, -1).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
internal async void SendPlayRequest(string url, string context = "")
|
internal async void SendPlayRequest(string url, string context = "")
|
||||||
{
|
{
|
||||||
// TODO: instead of having an empty context, one way to fix the bug with the playback time beyond the length of a song would be to provide a 1-song context, and it would be fixed.
|
// TODO: instead of having an empty context, one way to fix the bug with the playback time beyond the length of a song would be to provide a 1-song context, and it would be fixed.
|
||||||
await QueryAsync($"remote/play.json?uri={url}&context={context}", true, true, -1);
|
await QueryAsync($"remote/play.json?uri={url}&context={context}", true, true, -1).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
internal async void SendQueueRequest(string url)
|
internal async void SendQueueRequest(string url)
|
||||||
{
|
{
|
||||||
await QueryAsync("remote/play.json?uri=" + url + "?action=queue", true, true, -1);
|
await QueryAsync("remote/play.json?uri=" + url + "?action=queue", true, true, -1).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
internal StatusResponse GetNewStatus()
|
internal StatusResponse GetNewStatus()
|
||||||
@ -151,7 +151,7 @@ namespace SpotifyAPI.Local
|
|||||||
using (var wc = new ExtendedWebClient())
|
using (var wc = new ExtendedWebClient())
|
||||||
{
|
{
|
||||||
if (SpotifyLocalAPI.IsSpotifyRunning())
|
if (SpotifyLocalAPI.IsSpotifyRunning())
|
||||||
response = "[ " + await wc.DownloadStringTaskAsync(new Uri(address)) + " ]";
|
response = "[ " + await wc.DownloadStringTaskAsync(new Uri(address)).ConfigureAwait(false) + " ]";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
|
@ -57,7 +57,7 @@ namespace SpotifyAPI.Web
|
|||||||
Tuple<ResponseInfo, string> response;
|
Tuple<ResponseInfo, string> response;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Tuple<ResponseInfo, byte[]> raw = await DownloadRawAsync(url);
|
Tuple<ResponseInfo, byte[]> raw = await DownloadRawAsync(url).ConfigureAwait(false);
|
||||||
response = new Tuple<ResponseInfo, string>(raw.Item1, raw.Item2.Length > 0 ? _encoding.GetString(raw.Item2) : "{}");
|
response = new Tuple<ResponseInfo, string>(raw.Item1, raw.Item2.Length > 0 ? _encoding.GetString(raw.Item2) : "{}");
|
||||||
}
|
}
|
||||||
catch (WebException e)
|
catch (WebException e)
|
||||||
@ -91,7 +91,7 @@ namespace SpotifyAPI.Web
|
|||||||
webClient.Encoding = _encoding;
|
webClient.Encoding = _encoding;
|
||||||
webClient.Headers = _webClient.Headers;
|
webClient.Headers = _webClient.Headers;
|
||||||
|
|
||||||
byte[] data = await _webClient.DownloadDataTaskAsync(url);
|
byte[] data = await _webClient.DownloadDataTaskAsync(url).ConfigureAwait(false);
|
||||||
ResponseInfo info = new ResponseInfo()
|
ResponseInfo info = new ResponseInfo()
|
||||||
{
|
{
|
||||||
Headers = webClient.ResponseHeaders
|
Headers = webClient.ResponseHeaders
|
||||||
@ -108,7 +108,7 @@ namespace SpotifyAPI.Web
|
|||||||
|
|
||||||
public async Task<Tuple<ResponseInfo, T>> DownloadJsonAsync<T>(string url)
|
public async Task<Tuple<ResponseInfo, T>> DownloadJsonAsync<T>(string url)
|
||||||
{
|
{
|
||||||
Tuple<ResponseInfo, string> response = await DownloadAsync(url);
|
Tuple<ResponseInfo, string> response = await DownloadAsync(url).ConfigureAwait(false);
|
||||||
return new Tuple<ResponseInfo, T>(response.Item1, JsonConvert.DeserializeObject<T>(response.Item2, JsonSettings));
|
return new Tuple<ResponseInfo, T>(response.Item1, JsonConvert.DeserializeObject<T>(response.Item2, JsonSettings));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -138,7 +138,7 @@ namespace SpotifyAPI.Web
|
|||||||
Tuple<ResponseInfo, string> response;
|
Tuple<ResponseInfo, string> response;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Tuple<ResponseInfo, byte[]> data = await UploadRawAsync(url, body, method);
|
Tuple<ResponseInfo, byte[]> data = await UploadRawAsync(url, body, method).ConfigureAwait(false);
|
||||||
response = new Tuple<ResponseInfo, string>(data.Item1, data.Item2.Length > 0 ? _encoding.GetString(data.Item2) : "{}");
|
response = new Tuple<ResponseInfo, string>(data.Item1, data.Item2.Length > 0 ? _encoding.GetString(data.Item2) : "{}");
|
||||||
}
|
}
|
||||||
catch (WebException e)
|
catch (WebException e)
|
||||||
@ -171,7 +171,7 @@ namespace SpotifyAPI.Web
|
|||||||
webClient.Proxy = null;
|
webClient.Proxy = null;
|
||||||
webClient.Encoding = _encoding;
|
webClient.Encoding = _encoding;
|
||||||
webClient.Headers = _webClient.Headers;
|
webClient.Headers = _webClient.Headers;
|
||||||
byte[] data = await _webClient.UploadDataTaskAsync(url, method, _encoding.GetBytes(body));
|
byte[] data = await _webClient.UploadDataTaskAsync(url, method, _encoding.GetBytes(body)).ConfigureAwait(false);
|
||||||
ResponseInfo info = new ResponseInfo
|
ResponseInfo info = new ResponseInfo
|
||||||
{
|
{
|
||||||
Headers = _webClient.ResponseHeaders
|
Headers = _webClient.ResponseHeaders
|
||||||
@ -188,7 +188,7 @@ namespace SpotifyAPI.Web
|
|||||||
|
|
||||||
public async Task<Tuple<ResponseInfo, T>> UploadJsonAsync<T>(string url, string body, string method)
|
public async Task<Tuple<ResponseInfo, T>> UploadJsonAsync<T>(string url, string body, string method)
|
||||||
{
|
{
|
||||||
Tuple<ResponseInfo, string> response = await UploadAsync(url, body, method);
|
Tuple<ResponseInfo, string> response = await UploadAsync(url, body, method).ConfigureAwait(false);
|
||||||
return new Tuple<ResponseInfo, T>(response.Item1, JsonConvert.DeserializeObject<T>(response.Item2, JsonSettings));
|
return new Tuple<ResponseInfo, T>(response.Item1, JsonConvert.DeserializeObject<T>(response.Item2, JsonSettings));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user