Skip to content

Commit

Permalink
Player: handle exceptions when some record corrupted
Browse files Browse the repository at this point in the history
  + dont kill player, just wait untill it exit
  • Loading branch information
Antono Vasiljev committed May 5, 2012
1 parent c4746ef commit 65ca50c
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions lib/shelr/player.rb
Expand Up @@ -29,8 +29,12 @@ def self.play_dump(file)


def self.list def self.list
(Dir[File.join(Shelr::DATA_DIR, "**")] - ['.', '..']).sort.each do |dir| (Dir[File.join(Shelr::DATA_DIR, "**")] - ['.', '..']).sort.each do |dir|
metadata = JSON.parse(IO.read(File.join(dir, 'meta'))) begin
puts "#{metadata["recorded_at"]} : #{metadata["title"]}" metadata = JSON.parse(IO.read(File.join(dir, 'meta')))
puts "#{metadata["recorded_at"]} : #{metadata["title"]}"
rescue Errno::ENOENT
puts "Corrupted shellcast in #{dir}"
end
end end
end end


Expand All @@ -55,7 +59,7 @@ def play(options = {})


def start_sound_player def start_sound_player
return unless File.exist?(record_file('sound.ogg')) return unless File.exist?(record_file('sound.ogg'))
at_exit { system('stty echo') } # at_exit { system('stty echo') }
STDOUT.puts "=> Starting sound player..." STDOUT.puts "=> Starting sound player..."
@sox_pid = fork do @sox_pid = fork do
`play #{record_file('sound.ogg')} 2>&1` `play #{record_file('sound.ogg')} 2>&1`
Expand All @@ -65,7 +69,7 @@ def start_sound_player
def stop_sound_player def stop_sound_player
return unless File.exist?(record_file('sound.ogg')) return unless File.exist?(record_file('sound.ogg'))
STDOUT.puts "=> Stopping sound player..." STDOUT.puts "=> Stopping sound player..."
Process.kill("HUP", @sox_pid) Process.waitpid(@sox_pid)
end end


def self.scriptreplay(typescript_file, timing_file) def self.scriptreplay(typescript_file, timing_file)
Expand Down

0 comments on commit 65ca50c

Please sign in to comment.