Class: WillYouStartTheFansPlease::BackgroundAudio
- Inherits:
-
Object
- Object
- WillYouStartTheFansPlease::BackgroundAudio
- Defined in:
- lib/will_you_start_the_fans_please/background_audio.rb
Instance Attribute Summary collapse
-
#ending_file ⇒ Object
writeonly
Sets the attribute ending_file.
-
#loop_file ⇒ Object
writeonly
Sets the attribute loop_file.
Instance Method Summary collapse
-
#initialize ⇒ BackgroundAudio
constructor
A new instance of BackgroundAudio.
- #start_playback ⇒ Object
- #stop_playback ⇒ Object
Constructor Details
#initialize ⇒ BackgroundAudio
Returns a new instance of BackgroundAudio.
9 10 11 12 13 14 15 16 |
# File 'lib/will_you_start_the_fans_please/background_audio.rb', line 9 def initialize @loop_file = File.("../../../audio/loop.m4a", __FILE__) @ending_file = File.("../../../audio/ending.m4a", __FILE__) # puts 'playing audio...' # puts @loop_file self.start_playback end |
Instance Attribute Details
#ending_file=(value) ⇒ Object (writeonly)
Sets the attribute ending_file
5 6 7 |
# File 'lib/will_you_start_the_fans_please/background_audio.rb', line 5 def ending_file=(value) @ending_file = value end |
#loop_file=(value) ⇒ Object (writeonly)
Sets the attribute loop_file
5 6 7 |
# File 'lib/will_you_start_the_fans_please/background_audio.rb', line 5 def loop_file=(value) @loop_file = value end |
Instance Method Details
#start_playback ⇒ Object
18 19 20 |
# File 'lib/will_you_start_the_fans_please/background_audio.rb', line 18 def start_playback @stdin, @stdout, @stderr, @thread = Open3.popen3("while :; do afplay '" + @loop_file + "' ; done") end |
#stop_playback ⇒ Object
22 23 24 25 26 27 28 29 30 |
# File 'lib/will_you_start_the_fans_please/background_audio.rb', line 22 def stop_playback # puts 'stopping audio...' # puts @ending_file parent_thread = @thread.pid child_threads = `pgrep -P #{@thread.pid}`.split("\n").to_a Process.kill "INT", parent_thread child_threads.each{|pid| Process.kill "INT", pid.to_i } system("afplay '" + @ending_file + "'") end |