Module: MPD::Plugins::Controls

Included in:
MPD
Defined in:
lib/ruby-mpd/plugins/controls.rb

Overview

Commands for controlling playback.

Instance Method Summary collapse

Instance Method Details

#nextBoolean

Plays the next song in the playlist.

Returns:

  • (Boolean)

    returns true if successful.



7
8
9
# File 'lib/ruby-mpd/plugins/controls.rb', line 7

def next
  send_command :next
end

#pause=(toggle) ⇒ Boolean

Resume/pause playback.

Returns:

  • (Boolean)

    returns true if successful.



13
14
15
# File 'lib/ruby-mpd/plugins/controls.rb', line 13

def pause=(toggle)
  send_command :pause, toggle
end

#play(pos = nil) ⇒ Boolean

Begin/resume playing the queue.

Parameters:

  • pos (Integer) (defaults to: nil)

    Position in the playlist to start playing.

  • pos (Hash) (defaults to: nil)

    :id of the song where to start playing.

Returns:

  • (Boolean)

    returns true if successful.



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/ruby-mpd/plugins/controls.rb', line 21

def play(pos = nil)
  if pos.is_a?(Hash)
    if pos[:id]
      send_command :playid, priority, pos[:id]
    else
      raise ArgumentError, 'Only :id key is allowed!'
    end
  else
    send_command :play, pos
  end
end

#previousBoolean

Plays the previous song in the playlist.

Returns:

  • (Boolean)

    returns true if successful.



35
36
37
# File 'lib/ruby-mpd/plugins/controls.rb', line 35

def previous
  send_command :previous
end

#seek(time, options = {}) ⇒ Boolean

Seeks to the position in seconds within the current song. If prefixed by ‘+’ or ‘-’, then the time is relative to the current playing position.

Parameters:

  • time (Integer, String)

    Position within the current song.

  • options (Hash) (defaults to: {})

    Either :id or :pos can be specified.

Returns:

  • (Boolean)

    returns true if successful.

Since:

  • MPD 0.17



47
48
49
50
51
52
53
54
55
# File 'lib/ruby-mpd/plugins/controls.rb', line 47

def seek(time, options = {})
  if options[:id]
    send_command :seekid, options[:id], time
  elsif options[:pos]
    send_command :seek, options[:pos], time
  else
    send_command :seekcur, time
  end
end

#stopBoolean

Stop playing.

Returns:

  • (Boolean)

    returns true if successful.



59
60
61
# File 'lib/ruby-mpd/plugins/controls.rb', line 59

def stop
  send_command :stop
end