@@ -76,37 +76,65 @@ def playback
7676 #
7777 # # Play from a playlist, album from a specific index in that list.
7878 # # For example, play the 9th item on X playlist.
79- # device.play!(index: 5, context: "spotify:album:5ht7ItJgpBH7W6vJ5BqpPr")
79+ # device.play!(
80+ # index: 5,
81+ # context: "spotify:album:5ht7ItJgpBH7W6vJ5BqpPr",
82+ # position_ms: 0
83+ # )
8084 #
8185 # # Play any Spotify URI. Albums, artists, tracks, playlists, and more.
82- # device.play!(uri: "spotify:track:5MqkZd7a7u7N7hKMqquL2U")
86+ # device.play!(
87+ # uri: "spotify:track:5MqkZd7a7u7N7hKMqquL2U",
88+ # position_ms: 0
89+ # )
8390 #
8491 # # Similar to just uri, but you can define the context.
8592 # # Useful for playing a track that is part of a playlist, and you want the next
8693 # # songs to play from that particular context.
87- # device.play!(uri: "spotify:track:5MqkZd7a7u7N7hKMqquL2U", context: "spotify:album:5ht7ItJgpBH7W6vJ5BqpPr")
94+ # device.play!(
95+ # uri: "spotify:track:5MqkZd7a7u7N7hKMqquL2U",
96+ # context: "spotify:album:5ht7ItJgpBH7W6vJ5BqpPr",
97+ # position_ms: 0
98+ # )
99+ #
100+ # # Play a track, and immediately seek to 60 seconds.
101+ # device.play!(
102+ # index: 5,
103+ # context: "spotify:album:5ht7ItJgpBH7W6vJ5BqpPr",
104+ # position_ms: 60 * 1000
105+ # )
88106 #
89107 # @see https://developer.spotify.com/console/put-play/
90108 #
91109 # @param [Hash] config The play config you'd like to set. See code examples.
92110 # @return [Spotify::SDK::Connect::Device] self Return itself, so chained methods can be supported.
93111 #
112+ # rubocop:disable AbcSize
94113 def play! ( config )
95114 payload = case config . keys
96- when %i[ index context ]
97- { context_uri : config [ :context ] , offset : { position : config [ :index ] } }
98- when %i[ uri ]
99- { uris : [ config [ :uri ] ] }
100- when %i[ uri context ]
101- { context_uri : config [ :context ] , offset : { uri : config [ :uri ] } }
115+ when %i[ index context position_ms ]
116+ { context_uri : config [ :context ] ,
117+ offset : { position : config [ :index ] } ,
118+ position_ms : config [ :position_ms ] }
119+ when %i[ uri position_ms ]
120+ { uris : [ config [ :uri ] ] ,
121+ position_ms : config [ :position_ms ] }
122+ when %i[ uri context position_ms ]
123+ { context_uri : config [ :context ] ,
124+ offset : { uri : config [ :uri ] } ,
125+ position_ms : config [ :position_ms ] }
102126 else
103- raise "Unrecognized play instructions. See documentation for details."
127+ raise <<-ERROR . strip_heredoc . strip
128+ Unrecognized play instructions.
129+ See https://www.rubydoc.info/github/bih/spotify-ruby/Spotify/SDK/Connect/Device#play!-instance_method for details.
130+ ERROR
104131 end
105132
106133 parent . send_http_request ( :put , "/v1/me/player/play?device_id=%s" % id , http_options : { expect_nil : true } ,
107134 body : payload . to_json )
108135 self
109136 end
137+ # rubocop:enable AbcSize
110138
111139 ##
112140 # Resume the currently playing track on device.
0 commit comments