Class: Spotify::SDK::Connect::PlaybackState
- Defined in:
- lib/spotify/sdk/connect/playback_state.rb
Instance Attribute Summary
Attributes inherited from Model
Instance Method Summary collapse
-
#artist ⇒ Spotify::SDK::Artist
Get the main artist for the currently playing track.
-
#artists ⇒ Array
Get the artists for the currently playing track.
-
#device ⇒ Spotify::SDK::Connect::Device
Get the device the current playback is on.
-
#item ⇒ Spotify::SDK::Item
Get the item for the currently playing track.
-
#playing? ⇒ FalseClass, TrueClass
Is the current user playing a track?.
-
#position ⇒ Integer
What is the current position of the track?.
-
#position_percentage(decimal_points = 2) ⇒ Float
How much percentage of the track is the position currently in?.
-
#repeat_mode ⇒ Symbol
What repeat mode is the current playback set to?.
-
#shuffling? ⇒ FalseClass, TrueClass
Is the current playback set to shuffle?.
-
#time ⇒ Time
The current timestamp of the playback state.
Methods inherited from Model
alias_attribute, hash_selector, #initialize, #to_h, #to_json
Constructor Details
This class inherits a constructor from Spotify::SDK::Model
Instance Method Details
#artist ⇒ Spotify::SDK::Artist
Get the main artist for the currently playing track.
123 124 125 |
# File 'lib/spotify/sdk/connect/playback_state.rb', line 123 def artist artists.first end |
#artists ⇒ Array
Get the artists for the currently playing track.
109 110 111 112 113 |
# File 'lib/spotify/sdk/connect/playback_state.rb', line 109 def artists item[:artists].map do |artist| Spotify::SDK::Artist.new(artist, parent) end end |
#device ⇒ Spotify::SDK::Connect::Device
Get the device the current playback is on.
16 17 18 |
# File 'lib/spotify/sdk/connect/playback_state.rb', line 16 def device Spotify::SDK::Connect::Device.new(super, parent) end |
#item ⇒ Spotify::SDK::Item
Get the item for the currently playing track.
135 136 137 138 139 |
# File 'lib/spotify/sdk/connect/playback_state.rb', line 135 def item raise "Playback information is not available if user has a private session enabled" if device.private_session? Spotify::SDK::Item.new(to_h, parent) end |
#playing? ⇒ FalseClass, TrueClass
Is the current user playing a track?
29 |
# File 'lib/spotify/sdk/connect/playback_state.rb', line 29 alias_attribute :playing?, :is_playing |
#position ⇒ Integer
What is the current position of the track?
82 |
# File 'lib/spotify/sdk/connect/playback_state.rb', line 82 alias_attribute :position, :progress_ms |
#position_percentage(decimal_points = 2) ⇒ Float
How much percentage of the track is the position currently in?
95 96 97 98 99 |
# File 'lib/spotify/sdk/connect/playback_state.rb', line 95 def position_percentage(decimal_points=2) return nil if position.nil? ((position.to_f / item.duration.to_f) * 100).ceil(decimal_points) end |
#repeat_mode ⇒ Symbol
What repeat mode is the current playback set to?
Options:
:off => This means no repeat is set.
:context => This means it will repeat within the same context.
:track => This will repeat the same track.
56 57 58 |
# File 'lib/spotify/sdk/connect/playback_state.rb', line 56 def repeat_mode repeat_state.to_sym end |
#shuffling? ⇒ FalseClass, TrueClass
Is the current playback set to shuffle?
40 |
# File 'lib/spotify/sdk/connect/playback_state.rb', line 40 alias_attribute :shuffling?, :shuffle_state |
#time ⇒ Time
The current timestamp of the playback state
69 70 71 |
# File 'lib/spotify/sdk/connect/playback_state.rb', line 69 def time Time.at( / 1000) end |