Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implements transfer playback endpoint #163

Merged
merged 2 commits into from
Apr 23, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 21 additions & 4 deletions lib/src/endpoints/player.dart
Original file line number Diff line number Diff line change
Expand Up @@ -170,12 +170,12 @@ class PlayerEndpoint extends _MeEndpointBase {
}

/// Set the volume for the user’s current playback device.
/// [volumePercent] is required. The volume to set. Must be a value from 0 to
/// 100 inclusive.
/// [volumePercent] is required. The volume to set. Must be a value from `0` to
/// `100` inclusive.
/// [deviceId] is optional. If not provided, the user's currently active device
/// is the target.
/// [retrievePlaybackState] is optional. If true, the current playback state
/// will be retrieved. Defaults to true.
/// [retrievePlaybackState] is optional. If `true`, the current playback state
/// will be retrieved. Defaults to `true`.
Future<PlaybackState?> volume(int volumePercent,
{String? deviceId, bool retrievePlaybackState = true}) async {
assert(volumePercent >= 0 && volumePercent <= 100,
Expand All @@ -185,4 +185,21 @@ class PlayerEndpoint extends _MeEndpointBase {

return retrievePlaybackState ? playbackState() : null;
}

/// Transfer playback to a new device and determine if
/// it should start [play]ing. Default is `true`.
///
/// The `AuthorizationScope.connect.modifyPlaybackState` needs to be set.
/// [retrievePlaybackState] is optional. If `true`, the current playback state
/// will be retrieved. Defaults to `true`.
Future<PlaybackState?> transfer(String deviceId,
[bool play = true, bool retrievePlaybackState = true]) async {
assert(deviceId.isNotEmpty, 'No deviceId provided');
var jsonBody = jsonEncode({
'device_ids': [deviceId],
Copy link
Owner

@rinukkusu rinukkusu Apr 23, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was just about to comment on Spotify accepting an array but here we only send a single device. But then I read the docs real quick and I understand. Once again we are being spotified. 😆

'play': play
});
await _api._put(_path, jsonBody);
return retrievePlaybackState ? playbackState() : null;
}
}