Class: Play::Client
- Inherits:
-
Object
- Object
- Play::Client
- Defined in:
- lib/play/client.rb
Class Method Summary collapse
-
.loop ⇒ Object
The main event loop for an audio client.
-
.pause ⇒ Object
“Pauses” a client by stopping currently playing songs and setting up the pause temp file.
-
.pause_path ⇒ Object
The temp file we use to signify whether Play should be paused.
-
.paused? ⇒ Boolean
Are we currently paused?.
-
.playing? ⇒ Boolean
Are we currently playing? Look at the process list and check it out.
-
.say(msg) ⇒ Object
Say things over the speakers, lol.
-
.stop ⇒ Object
Stop the music, and stop the music server.
-
.volume(number) ⇒ Object
Set the volume level of the client.
Class Method Details
.loop ⇒ Object
The main event loop for an audio client. It will loop through each song in the queue, unless it’s paused.
Returns nothing.
7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/play/client.rb', line 7 def self.loop while true Signal.trap("INT") { exit! } if paused? sleep(1) else system("afplay", Song.play_next_in_queue.path) end end end |
.pause ⇒ Object
“Pauses” a client by stopping currently playing songs and setting up the pause temp file.
Returns nothing.
30 31 32 33 |
# File 'lib/play/client.rb', line 30 def self.pause paused? ? `rm -f #{pause_path}` : `touch #{pause_path}` `killall afplay > /dev/null 2>&1` end |
.pause_path ⇒ Object
The temp file we use to signify whether Play should be paused.
Returns the String path of the pause file.
22 23 24 |
# File 'lib/play/client.rb', line 22 def self.pause_path '/tmp/play_is_paused' end |
.paused? ⇒ Boolean
Are we currently paused?
Returns the Boolean value of whether we’re paused.
38 39 40 |
# File 'lib/play/client.rb', line 38 def self.paused? File.exist?(pause_path) end |
.playing? ⇒ Boolean
Are we currently playing? Look at the process list and check it out.
Returns true if we’re playing, false if we aren’t.
45 46 47 |
# File 'lib/play/client.rb', line 45 def self. `ps aux | grep afplay | grep -v grep | wc -l | tr -d ' '`.chomp != '0' end |
.say(msg) ⇒ Object
Say things over the speakers, lol.
Returns nothing.
60 61 62 |
# File 'lib/play/client.rb', line 60 def self.say(msg) system "say #{msg}" end |
.stop ⇒ Object
Stop the music, and stop the music server.
Returns nothing.
52 53 54 55 |
# File 'lib/play/client.rb', line 52 def self.stop `killall afplay > /dev/null 2>&1` `kill \`ps ax | grep "play -d" | cut -d ' ' -f 1\`` end |
.volume(number) ⇒ Object
Set the volume level of the client.
number - The Integer volume level. This should be a number between 0
and 10, with "0" being "muted" and "10" being "real real loud"
Returns nothing.
70 71 72 |
# File 'lib/play/client.rb', line 70 def self.volume(number) system "osascript -e 'set volume #{number}' 2>/dev/null" end |