Class: Anyplayer::Mpd

Inherits:
Player
  • Object
show all
Defined in:
lib/anyplayer/players/mpd.rb

Constant Summary

Constants inherited from Player

Player::DEFAULT_VOTES_TO_SKIP

Instance Method Summary collapse

Methods inherited from Player

#name, #paused?, #platforms, #vote, #votes

Constructor Details

#initializeMpd

Returns a new instance of Mpd.



9
10
11
12
# File 'lib/anyplayer/players/mpd.rb', line 9

def initialize
  @mpc = false
  super
end

Instance Method Details

#albumObject



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

def album
  current_song&.album
end

#artistObject



59
60
61
# File 'lib/anyplayer/players/mpd.rb', line 59

def artist
  current_song&.artist
end

#hostObject



71
72
73
# File 'lib/anyplayer/players/mpd.rb', line 71

def host
  ENV["MPD_HOST"] || super
end

#launched?Boolean

Returns:

  • (Boolean)


67
68
69
# File 'lib/anyplayer/players/mpd.rb', line 67

def launched?
  !!(@mpc && @mpc.connected? || connect)
end

#nextObject



35
36
37
38
# File 'lib/anyplayer/players/mpd.rb', line 35

def next
  mpc.next
  super
end

#pauseObject



24
25
26
27
28
# File 'lib/anyplayer/players/mpd.rb', line 24

def pause
  # ruby-mpd tries to send an additional argument to the MPD server
  # which at least doesn't work with Mopidy.
  mpc.send_command :pause
end

#playObject



20
21
22
# File 'lib/anyplayer/players/mpd.rb', line 20

def play
  mpc.play
end

#playpauseObject



14
15
16
17
18
# File 'lib/anyplayer/players/mpd.rb', line 14

def playpause
  mpc.paused? &&
    mpc.send_command(:play) ||
    mpc.send_command(:pause)
end

#prevObject



30
31
32
33
# File 'lib/anyplayer/players/mpd.rb', line 30

def prev
  mpc.previous
  super
end

#trackObject



52
53
54
55
56
57
# File 'lib/anyplayer/players/mpd.rb', line 52

def track
  song = current_song
  return unless song

  song.title || File.basename(song.file)
end

#voldownObject



40
41
42
# File 'lib/anyplayer/players/mpd.rb', line 40

def voldown
  mpc.volume -= 10
end

#volumeObject



48
49
50
# File 'lib/anyplayer/players/mpd.rb', line 48

def volume
  mpc.volume
end

#volupObject



44
45
46
# File 'lib/anyplayer/players/mpd.rb', line 44

def volup
  mpc.volume += 10
end