class Spotify::SDK::Connect::PlaybackState
Public Instance Methods
Get the main artist for the currently playing track.
@example
@sdk.connect.playback.artist
@return [Spotify::SDK::Artist] artist The main artist of the track.
# File lib/spotify/sdk/connect/playback_state.rb, line 123 def artist artists.first end
Get the artists for the currently playing track.
@example
@sdk.connect.playback.artists
@return [Array] artists An array of artists wrapped in Spotify::SDK::Artist
# 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
Get the device the current playback is on.
@example
device = @sdk.connect.devices[0] device.playback.device
@return [Spotify::SDK::Connect::Device] self Return the device object.
# File lib/spotify/sdk/connect/playback_state.rb, line 16 def device Spotify::SDK::Connect::Device.new(super, parent) end
Get the item for the currently playing track.
@example
@sdk.connect.playback.item
@return [Spotify::SDK::Item] item The currently playing track, wrapped in Spotify::SDK::Item
# 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
Is the current user playing a track?
@example
playback = @sdk.connect.playback playback.playing?
@return [FalseClass,TrueClass] is_playing True if user is currently performing playback.
# File lib/spotify/sdk/connect/playback_state.rb, line 29 alias_attribute :playing?, :is_playing
What is the current position of the track?
@example
playback = @sdk.connect.playback playback.position
@return [Integer] position_ms In milliseconds, the position of the track.
# File lib/spotify/sdk/connect/playback_state.rb, line 82 alias_attribute :position, :progress_ms
How much percentage of the track is the position currently in?
@example
playback = @sdk.connect.playback playback.position_percentage # => 7.30 playback.position_percentage(4) # => 7.3039
@param [Integer] decimal_points How many decimal points to return @return [Float] percentage Completion percentage. Rounded to 2 decimal places.
# 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
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.
@example
playback = @sdk.connect.playback playback.repeat # :off, :context, or :track
@return [Symbol] repeat_mode
Either :off, :context, or :track
# File lib/spotify/sdk/connect/playback_state.rb, line 56 def repeat_mode repeat_state.to_sym end
Is the current playback set to shuffle?
@example
playback = @sdk.connect.playback playback.shuffling?
@return [FalseClass,TrueClass] is_shuffling True if shuffle is set.
# File lib/spotify/sdk/connect/playback_state.rb, line 40 alias_attribute :shuffling?, :shuffle_state
The current timestamp of the playback state
@example
playback = @sdk.connect.playback playback.time
@return [Time] time The accuracy time of the playback state.
# File lib/spotify/sdk/connect/playback_state.rb, line 69 def time Time.at(timestamp / 1000) end