/ Published in: Ruby
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
require 'rubygems' class Player @@sound_path = '' @@sound_app = 'mpg321' @@process_devnull = '> /dev/null 2>&1' @@process_bg = '&' def self.sound_path=(value) @@sound_path = value end def self.sound_app=(value) @@sound_app = value end def self.process_devnull=(value) @@process_devnull = value end def self.process_bg=(value) @@process_bg = value end def self.play(file) cmd = "#{@@sound_app} #{@@sound_path + file} #{@@process_devnull} #{@@process_bg}" system cmd end end files = Dir.glob(File.join("/home/buildmaster/Desktop/sounds/error", "*.mp3")) Player.play(files[rand(files.size)])