Skip to content

Commit

Permalink
Merge pull request #192 from hayribakici/#191_404
Browse files Browse the repository at this point in the history
Catching empty response on `PlaybackState`
  • Loading branch information
rinukkusu authored Feb 12, 2024
2 parents 1c7dde1 + 883fd56 commit f2f0d25
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions lib/src/endpoints/player.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,22 @@ class PlayerEndpoint extends _MeEndpointBase {
}

/// Returns the current playback state, including progress, track
/// and active device.
/// and active device. Returns an empty [PlaybackState] object when
/// no playback context has been started.
@Deprecated('Use [playbackState] instead')
Future<PlaybackState> player([String? market]) async {
return playbackState(Market.values.asNameMap()[market]);
}

/// Returns the current playback state, including progress, track
/// and active device.
/// and active device. Returns an empty [PlaybackState] object when
/// no playback context has been started.
Future<PlaybackState> playbackState([Market? market]) async {
var jsonString =
await _api._get('$_path?${_buildQuery({'market': market?.name})}');
var jsonString = await _api._get('$_path?${_buildQuery({'market': market?.name})}');

if (jsonString.isEmpty) {
return PlaybackState();
}
final map = json.decode(jsonString);
return PlaybackState.fromJson(map);
}
Expand Down

0 comments on commit f2f0d25

Please sign in to comment.