Class: RubyAfplay::Player

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_afplay/player.rb

Instance Method Summary collapse

Constructor Details

#initialize(file_path, options = {}) ⇒ Player

Returns a new instance of Player.



4
5
6
# File 'lib/ruby_afplay/player.rb', line 4

def initialize(file_path, options = {})
  @command = file_path + build_options_string(options)
end

Instance Method Details

#pauseObject



17
18
19
20
# File 'lib/ruby_afplay/player.rb', line 17

def pause
  # send a stop signal to afplay using the process_id
  Process.kill("SIGSTOP", @process_id)
end

#playObject



8
9
10
11
12
13
14
15
# File 'lib/ruby_afplay/player.rb', line 8

def play
  if @process_id
    # resume playing if the process is already running
    Process.kill("SIGCONT", @process_id)
  else
    start_process!
  end
end

#stopObject



22
23
24
25
26
27
# File 'lib/ruby_afplay/player.rb', line 22

def stop
  # send a kill signal to aflpay using the process_id
  Process.kill("SIGKILL", @process_id)
  # detach the process
  detach_process!
end