Skip to content

Commit

Permalink
Rename method for fetching playback context
Browse files Browse the repository at this point in the history
  • Loading branch information
calledude committed Feb 25, 2024
1 parent f10fa75 commit f4412e8
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions SpotifyVolumeExtension/Monitoring/SpotifyMonitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,8 @@ public bool SpotifyIsRunning()

private async Task<bool> IsPlayingMusic()
{
var pb = await _spotifyClient.GetPlaybackContext();
return pb?.IsPlaying ?? false;
var currentPlaybackContext = await _spotifyClient.GetCurrentPlayback();
return currentPlaybackContext?.IsPlaying ?? false;
}

public void Dispose()
Expand Down
2 changes: 1 addition & 1 deletion SpotifyVolumeExtension/Monitoring/StatusController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public async Task<bool> CheckStateImmediate()
{
if (_processMonitorService.ProcessIsRunning())
{
var playbackContext = await _spotifyClient.GetPlaybackContext();
var playbackContext = await _spotifyClient.GetCurrentPlayback();
await OnStateChange(playbackContext?.IsPlaying ?? _lastState, playbackContext);
}
else
Expand Down
2 changes: 1 addition & 1 deletion SpotifyVolumeExtension/Spotify/SpotifyApiClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public SpotifyApiClient(Retry retrier, SpotifyClient client)
_client = client;
}

public async Task<CurrentlyPlayingContext?> GetPlaybackContext()
public async Task<CurrentlyPlayingContext?> GetCurrentPlayback()
=> await _retrier.Wrap(() => _client.Player.GetCurrentPlayback());

public async Task<bool> SetVolume(int volumePercent)
Expand Down
8 changes: 4 additions & 4 deletions SpotifyVolumeExtension/Volume/SpotifyVolumeController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,16 @@ public override void Stop()
protected override async Task<int> GetBaselineVolume()
{
_logger.LogTrace("Fetching baseline volume");
var playbackContext = await _spotifyClient.GetPlaybackContext();
while (!playbackContext.IsPlaying)
var playbackContext = await _spotifyClient.GetCurrentPlayback();
while (playbackContext == null || !playbackContext.IsPlaying)
{
_logger.LogTrace("Failed to fetch baseline volume");
await Task.Delay(500);
playbackContext = await _spotifyClient.GetPlaybackContext();
playbackContext = await _spotifyClient.GetCurrentPlayback();
}

_logger.LogTrace("Fetched baseline volume");
return playbackContext.Device.VolumePercent.Value;
return playbackContext.Device.VolumePercent ?? 0;
}

private async Task VolumeKeyPressed(MediaKeyEventArgs m)
Expand Down

0 comments on commit f4412e8

Please sign in to comment.