Class: RSpotify::Player
Instance Attribute Summary
Attributes inherited from Base
#external_urls, #href, #id, #type, #uri
Instance Method Summary collapse
- #currently_playing ⇒ Object
-
#initialize(user, options = {}) ⇒ Player
constructor
A new instance of Player.
-
#pause ⇒ Object
Pause the user’s currently active player.
-
#play(device_id = nil, params = {}) ⇒ Object
Play the user’s currently active player or specific device If ‘device_id` is not passed, the currently active spotify app will be triggered.
-
#play_context(device_id = nil, uri) ⇒ Object
Allow user to play a specific context(albums, artists & playlists).
- #play_track(device_id = nil, uri) ⇒ Object
-
#play_tracks(device_id = nil, uris) ⇒ Object
Allow user to play a list of tracks.
- #playing? ⇒ Boolean
- #seek(position_ms) ⇒ Object
-
#volume(percent) ⇒ Object
Update the user’s currently active player volume.
Methods inherited from Base
#complete!, #embed, find, #method_missing, #respond_to?, search
Constructor Details
#initialize(user, options = {}) ⇒ Player
Returns a new instance of Player.
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/rspotify/player.rb', line 4 def initialize(user, = {}) @user = user @repeat_state = ['repeat_state'] @shuffle_state = ['shuffle_state'] @progress = ['progress_ms'] @is_playing = ['is_playing'] @track = if ['track'] Track.new ['track'] end @device = if ['device'] Device.new ['device'] end end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class RSpotify::Base
Instance Method Details
#currently_playing ⇒ Object
93 94 95 96 97 98 |
# File 'lib/rspotify/player.rb', line 93 def url = "me/player/currently-playing" response = RSpotify.resolve_auth_request(@user.id, url) return response if RSpotify.raw_response Track.new response["item"] end |
#pause ⇒ Object
Pause the user’s currently active player
78 79 80 81 |
# File 'lib/rspotify/player.rb', line 78 def pause url = 'me/player/pause' User.oauth_put(@user.id, url, {}) end |
#play(device_id = nil, params = {}) ⇒ Object
Play the user’s currently active player or specific device If ‘device_id` is not passed, the currently active spotify app will be triggered
66 67 68 69 70 71 |
# File 'lib/rspotify/player.rb', line 66 def play(device_id = nil, params = {}) url = "me/player/play" url = device_id.nil? ? url : url+"?device_id=#{device_id}" User.oauth_put(@user.id, url, params.to_json) end |
#play_context(device_id = nil, uri) ⇒ Object
Allow user to play a specific context(albums, artists & playlists). If ‘device_id` is not passed, the currently active spotify app will be triggered
31 32 33 34 |
# File 'lib/rspotify/player.rb', line 31 def play_context(device_id=nil, uri) params = {"context_uri": uri} play(device_id, params) end |
#play_track(device_id = nil, uri) ⇒ Object
55 56 57 58 |
# File 'lib/rspotify/player.rb', line 55 def play_track(device_id=nil, uri) params = {"uris": [uri]} play(device_id, params) end |
#play_tracks(device_id = nil, uris) ⇒ Object
Allow user to play a list of tracks. If ‘device_id` is not passed, the currently active spotify app will be triggered
43 44 45 46 |
# File 'lib/rspotify/player.rb', line 43 def play_tracks(device_id=nil, uris) params = {"uris": uris} play(device_id, params) end |
#playing? ⇒ Boolean
21 22 23 |
# File 'lib/rspotify/player.rb', line 21 def end |
#seek(position_ms) ⇒ Object
100 101 102 103 |
# File 'lib/rspotify/player.rb', line 100 def seek(position_ms) url = "/me/player/seek?position_ms=#{position_ms}" User.oauth_put(@user.id, url, {}) end |
#volume(percent) ⇒ Object
Update the user’s currently active player volume
88 89 90 91 |
# File 'lib/rspotify/player.rb', line 88 def volume(percent) url = "me/player/volume?volume_percent=#{percent}" User.oauth_put(@user.id, url, {}) end |