❔ I want to only have hours, minutes, secs, on my count up for my music:

here code:
private async Task UpdateSongPositionAndDuration(string accessToken)
{
string playbackEndpoint = "https://api.spotify.com/v1/me/player/currently-playing";
_httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);
var response = await _httpClient.GetAsync(playbackEndpoint);
var responseString = await response.Content.ReadAsStringAsync();
var responseObject = JObject.Parse(responseString);
if (responseObject != null && responseObject["progress_ms"] != null)
{
// Assuming you have retrieved the current position from the Spotify API response
TimeSpan songPosition = TimeSpan.FromMilliseconds((double)responseObject["progress_ms"]);
TimeSpan songDuration = TimeSpan.FromMilliseconds((double)responseObject["item"]["duration_ms"]);


// Set the song duration and position
SongDuration = songDuration;
SongPosition = songPosition;

// Calculate the progress percentage
// Calculate the progress percentage
TimeSpan time = DateTime.Now.TimeOfDay;
TimeSpan truncatedTime = TimeSpan.FromSeconds(Math.Truncate(time.TotalSeconds));
TimeSpan songProgress = new TimeSpan(truncatedTime.Hours, truncatedTime.Minutes, truncatedTime.Seconds);
SongProgress = songProgress;



}
else
{
// Set default values when data is not available
SongDuration = TimeSpan.Zero;
SongPosition = TimeSpan.Zero;
SongProgress = TimeSpan.Zero;
}
}
private async Task UpdateSongPositionAndDuration(string accessToken)
{
string playbackEndpoint = "https://api.spotify.com/v1/me/player/currently-playing";
_httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);
var response = await _httpClient.GetAsync(playbackEndpoint);
var responseString = await response.Content.ReadAsStringAsync();
var responseObject = JObject.Parse(responseString);
if (responseObject != null && responseObject["progress_ms"] != null)
{
// Assuming you have retrieved the current position from the Spotify API response
TimeSpan songPosition = TimeSpan.FromMilliseconds((double)responseObject["progress_ms"]);
TimeSpan songDuration = TimeSpan.FromMilliseconds((double)responseObject["item"]["duration_ms"]);


// Set the song duration and position
SongDuration = songDuration;
SongPosition = songPosition;

// Calculate the progress percentage
// Calculate the progress percentage
TimeSpan time = DateTime.Now.TimeOfDay;
TimeSpan truncatedTime = TimeSpan.FromSeconds(Math.Truncate(time.TotalSeconds));
TimeSpan songProgress = new TimeSpan(truncatedTime.Hours, truncatedTime.Minutes, truncatedTime.Seconds);
SongProgress = songProgress;



}
else
{
// Set default values when data is not available
SongDuration = TimeSpan.Zero;
SongPosition = TimeSpan.Zero;
SongProgress = TimeSpan.Zero;
}
}
6 Replies
Buddy
Buddy2y ago
$code
MODiX
MODiX2y ago
To post C# code type the following: ```cs // code here ``` Get an example by typing $codegif in chat If your code is too long, post it to: https://paste.mod.gg/
JakenVeina
JakenVeina2y ago
is there a question here somewhere?
🖤Getakorone🖤
in title but I want only hh:mm:ss to show not hh:mm:ss:ffffff
JakenVeina
JakenVeina2y ago
where is the code that displays that value?
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server