#!/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 =end require 'rand' # the directory variable holding the mp3 directory d = nil # the time in seconds to play another song timerList = [4, 5, 6, 7] # The program to use to play sounds program = 'C:/Tools/mplayer/mplayer.exe' # The mp3 directory soundDir = "C:/Projects/Python/mp3list/sounds" begin d = Dir.open(soundDir) rescue Errno::ENOENT #raise "Couldn't open #{dir} for reading: #{$!}" end files = Array.new # add all the songs to a list d.each do |file| filename = File.join(soundDir, file) if File.extname(filename) == "" next end # There is no -T equivalent in Ruby, but we can still test emptiness files.push(filename) end # loop all the time while true begin # sleep for some time sleep(timerList.pick) # play the song IO.popen( program + " " + files.pick, "r") # wait for the process to terminate Process.wait rescue Interrupt puts "Program terminated by the user" exit() end end