summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--libmpd.rb74
-rw-r--r--libmpd/playbackcontrol.rb79
2 files changed, 81 insertions, 72 deletions
diff --git a/libmpd.rb b/libmpd.rb
index ca96290..13bdf4b 100644
--- a/libmpd.rb
+++ b/libmpd.rb
@@ -5,6 +5,7 @@
# See http://www.gnu.org/licenses/gpl.txt for the full license text.
require 'socket'
+require 'libmpd/playbackcontrol'
require 'libmpd/playbackoptions'
require 'libmpd/status'
@@ -21,6 +22,7 @@ class FalseClass # :nodoc:
end
class MPD
+ include MPDPlaybackControl
include MPDPlaybackOptions
include MPDStatus
@@ -69,57 +71,6 @@ class MPD
return hash
end
- # Begins playing the playlist. If argument is supplied, begin at specified
- # song position.
- def play songpos=false
- command = 'play'
- command << ' ' + songpos.to_s if songpos
-
- return send_request command
- end
-
- # Begins playing the playlist. If argument is supplied, begin at specified
- # song id.
- def playid songid=false
- command = 'playid'
- command << ' ' + songid.to_s if songid
-
- return send_request command
- end
-
- # Sets pause state.
- #
- # Accepts an argument of _true_ to enable or _false_ to disable.
- # If no argument is given, defaults to _true_.
- def pause state=true
- return send_request 'pause %s' % state.to_i
- end
-
- # Stops playing.
- def stop
- return send_request 'stop'
- end
-
- # Plays next song in the playlist.
- def next
- return send_request 'next'
- end
-
- # Plays previous song in the playlist.
- def previous
- return send_request 'previous'
- end
-
- # Seeks to the given position of the given song.
- def seek songpos, time
- return send_request 'seek %s %s' % [songpos, time]
- end
-
- # Seeks to the given position of the given song id.
- def seekid songid, time
- return send_request 'seekid %s %s' % [songid, time]
- end
-
# Adds the specified file to the playlist. (Directories add recursively.)
def add uri
return send_request 'add "%s"' % uri
@@ -161,27 +112,6 @@ class MPD
return split_and_hash send_request 'search %s "%s"' % [type, what]
end
- # Returns +true+ if playing.
- # Otherwise, returns +false+.
- def playing?
- return true if status[:state] == 'play'
- return false
- end
-
- # Returns +true+ if paused.
- # Otherwise, returns +false+.
- def paused?
- return true if status[:state] == 'pause'
- return false
- end
-
- # Returns +true+ if stopped.
- # Otherwise, returns +false+.
- def stopped?
- return true if status[:state] == 'stop'
- return false
- end
-
private :generate_hash
private :get_response
private :split_and_hash
diff --git a/libmpd/playbackcontrol.rb b/libmpd/playbackcontrol.rb
new file mode 100644
index 0000000..d37ed49
--- /dev/null
+++ b/libmpd/playbackcontrol.rb
@@ -0,0 +1,79 @@
+#!/usr/bin/env ruby
+#
+# Copyright 2009 David Vazgenovich Shakaryan <dvshakaryan@gmail.com>
+# Distributed under the terms of the GNU General Public License v3.
+# See http://www.gnu.org/licenses/gpl.txt for the full license text.
+
+module MPDPlaybackControl
+ # Begins playing the playlist. If argument is supplied, begin at specified
+ # song position.
+ def play songpos=false
+ command = 'play'
+ command << ' ' + songpos.to_s if songpos
+
+ return send_request command
+ end
+
+ # Begins playing the playlist. If argument is supplied, begin at specified
+ # song id.
+ def playid songid=false
+ command = 'playid'
+ command << ' ' + songid.to_s if songid
+
+ return send_request command
+ end
+
+ # Sets pause state.
+ #
+ # Accepts an argument of _true_ to enable or _false_ to disable.
+ # If no argument is given, defaults to _true_.
+ def pause state=true
+ return send_request 'pause %s' % state.to_i
+ end
+
+ # Stops playing.
+ def stop
+ return send_request 'stop'
+ end
+
+ # Plays next song in the playlist.
+ def next
+ return send_request 'next'
+ end
+
+ # Plays previous song in the playlist.
+ def previous
+ return send_request 'previous'
+ end
+
+ # Seeks to the given position of the given song.
+ def seek songpos, time
+ return send_request 'seek %s %s' % [songpos, time]
+ end
+
+ # Seeks to the given position of the given song id.
+ def seekid songid, time
+ return send_request 'seekid %s %s' % [songid, time]
+ end
+
+ # Returns +true+ if playing.
+ # Otherwise, returns +false+.
+ def playing?
+ return true if status[:state] == 'play'
+ return false
+ end
+
+ # Returns +true+ if paused.
+ # Otherwise, returns +false+.
+ def paused?
+ return true if status[:state] == 'pause'
+ return false
+ end
+
+ # Returns +true+ if stopped.
+ # Otherwise, returns +false+.
+ def stopped?
+ return true if status[:state] == 'stop'
+ return false
+ end
+end