Skip to content

Commit

Permalink
fixes bug
Browse files Browse the repository at this point in the history
  • Loading branch information
hayribakici authored and rinukkusu committed Feb 18, 2024
1 parent 131c370 commit fec57d4
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
18 changes: 18 additions & 0 deletions example/example_auth.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ void main() async {
exit(0);
}
await _user(spotify);
await _play(spotify);
await _currentlyPlaying(spotify);
await _devices(spotify);
await _followingArtists(spotify);
Expand Down Expand Up @@ -306,6 +307,23 @@ Future<Iterable<Track>> _getPlaylistTracks(
return (await tracksPage.first()).items ?? [];
}

Future<PlaybackState?> _play(SpotifyApi spotify) async {
var track = await spotify.tracks.get('6zW80jVqLtgSF1yCtGHiiD');
print('Playing "${track.name} - ${track.artists?.first.name}" with track context for 10 s');
var result = await spotify.player.startWithTracks(['spotify:track:6zW80jVqLtgSF1yCtGHiiD?si=99fd66ccb2464bad'], positionMs: 10000);
sleep(Duration(seconds: 10));
print('Pausing...');
spotify.player.pause();
var album = await spotify.albums.get('0rwbMKjNkp4ehQTwf9V2Jk');
track = await spotify.tracks.get('4VnDmjYCZkyeqeb0NIKqdA');
print('Playing album "${album.name} - ${album.artists?.first.name}" with uri context');
print('and offset to "${track.name} - ${track.artists?.first.name}" for 10 s');
result = await spotify.player.startWithContext('spotify:album:0rwbMKjNkp4ehQTwf9V2Jk?si=HA-mX2mPQ1CUp7ExfdDt2g', offset: UriOffset('spotify:track:4VnDmjYCZkyeqeb0NIKqdA'));
sleep(Duration(seconds: 10));

return result;
}

FutureOr<Null> _prettyPrintError(Object error) {
if (error is SpotifyException) {
print('${error.status} : ${error.message}');
Expand Down
5 changes: 2 additions & 3 deletions lib/src/models/player.dart
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ class StartOrResumeOptions extends Object {
List<String>? uris;

/// Optional. Indicates from where in the context playback should start.
/// Only available when context_uri corresponds to an album or playlist object
/// Only available when [contextUri] corresponds to an album or playlist object
@JsonKey(toJson: _offsetToJson)
Offset? offset;

Expand All @@ -150,8 +150,7 @@ class StartOrResumeOptions extends Object {

Map<String, dynamic> toJson() => _$StartOrResumeOptionsToJson(this);

static Map<String, dynamic> _offsetToJson(Offset? offset) =>
offset?.toJson() ?? {};
static Map<String, dynamic>? _offsetToJson(Offset? offset) => offset?.toJson();
}

abstract class Offset {
Expand Down

0 comments on commit fec57d4

Please sign in to comment.