Class: Anyplayer::Player

Inherits:
Object
  • Object
show all
Defined in:
lib/anyplayer/player.rb

Overview

Default Player class that is inherited by all players.

All players should override these methods:

launched? (return bool)
next
prev
play
pause
playpause
track     (return string)
artist    (return string)
album     (return string)
voldown
volup
volume    (return int)
playing?  (return bool)
paused?   (return bool)

Constant Summary collapse

DEFAULT_VOTES_TO_SKIP =
5

Instance Method Summary collapse

Constructor Details

#initializePlayer

Returns a new instance of Player.



21
22
23
# File 'lib/anyplayer/player.rb', line 21

def initialize
  @votes = 0
end

Instance Method Details

#launched?Boolean

Return true if the player is currently launched

Returns:

  • (Boolean)


26
27
28
# File 'lib/anyplayer/player.rb', line 26

def launched?
  false
end

#nameObject

Player name defaults to the classe’s, feel free to override it Example:

player.name # => iTunes


33
34
35
# File 'lib/anyplayer/player.rb', line 33

def name
  self.class.to_s.gsub(/^.*::/, "")
end

#nextObject

Tell the player to go the the next song This resets the votes, so be sure to call super in children



63
64
65
# File 'lib/anyplayer/player.rb', line 63

def next
  reset_votes
end

#paused?Boolean

Default paused is not playing

Returns:

  • (Boolean)


38
39
40
# File 'lib/anyplayer/player.rb', line 38

def paused?
  !playing?
end

#platformsObject

Operating systems where this player should work



74
75
76
# File 'lib/anyplayer/player.rb', line 74

def platforms
  [:mac, :windows, :linux, :unix]
end

#playpauseObject

Tells the player to toggle the pause state



43
44
45
# File 'lib/anyplayer/player.rb', line 43

def playpause
  paused? ? play : pause
end

#prevObject

Tell the player to go to the previous song This resets the votes, so be sur eto call super in children



69
70
71
# File 'lib/anyplayer/player.rb', line 69

def prev
  reset_votes
end

#vote(votes_to_skip = DEFAULT_VOTES_TO_SKIP) ⇒ Object

Vote to skip this song



48
49
50
51
52
53
54
# File 'lib/anyplayer/player.rb', line 48

def vote(votes_to_skip = DEFAULT_VOTES_TO_SKIP)
  @votes += 1
  if @votes >= votes_to_skip
    self.next
    reset_votes
  end
end

#votesObject

Returns the number of votes to skip this song



57
58
59
# File 'lib/anyplayer/player.rb', line 57

def votes
  @votes
end