5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
# File 'lib/capistrano/jukebox.rb', line 5
def self.load_into(configuration)
configuration.load do
on :before, :only => :deploy do
file = configuration[:file]
file = jeopardy_song if file.nil?
start_playing(file)
end
on :after, :only => :deploy do
stop_playing
end
namespace :jukebox do
desc 'Start playing music on the jukebox'
task :play, :roles => :app, :except => {:no_release => true} do
file = configuration[:file]
file = jeopardy_song if file.nil?
start_playing(file)
end
desc 'Stop the jukebox from playing music'
task :stop, :roles => :app, :except => {:no_release => true} do
puts "You have forced the jukebox to stop the music."
stop_playing
end
end
def start_playing(file)
puts "Jukebox is starting to play '#{file}'"
@pid = fork do
exec("mplayer #{file} -really-quiet -framedrop -cache 16384 -cache-min 20/100")
end
end
def stop_playing
unless @pid.nil?
::Process.kill("TERM", @pid)
else
exec("killall mplayer")
end
end
def jeopardy_song
File.expand_path('../../../music/jeopardy_thinking.mp3', __FILE__)
end
end
end
|