Public feed
#725053
#!/usr/bin/env ruby=begin Author : Mr. Cheeks Description : A program to fight against nasty neighbors The program plays random noises at random times So if the landlord comes he'll hear nothing :p Note : Make sure you add sounds like cows, dogs in your directory! :p =endrequire 'rand'class MPlayer attr_accessor :soundDir, :program, :timerList, :playlist def initialize @playlist = Array.new end def populate d = nil begin d = Dir.open(@soundDir) rescue Errno::ENOENT raise "Couldn't open #{d} for reading" end # add all the songs to a list d.each do |file| filename = File.join(@soundDir, file) if File.extname(filename) == "" next end puts 'Adding ' + filename + ' to playlist' # There is no -T equivalent in Ruby, but we can still test emptiness playlist.push(filename) end end def play(sound) puts 'Playing:' + sound IO.popen( @program + " " + sound, "r") # wait for the process to terminate Process.wait end end player = MPlayer.newplayer.soundDir = "C:/Projects/Python/mp3list/sounds"player.program = 'C:/Tools/mplayer/mplayer.exe'player.timerList = [1900, 2300, 3200, 3600, 2700]player.populate# loop all the timewhile true begin # sleep for some time timer = player.timerList.pick puts timer sleep(timer) player.play(player.playlist.pick) rescue Interrupt puts "Program terminated by the user" exit() end end