Skip to content

Instantly share code, notes, and snippets.

@abeeku
Forked from tobytripp/audio_test.rb
Created May 14, 2011 17:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abeeku/972406 to your computer and use it in GitHub Desktop.
Save abeeku/972406 to your computer and use it in GitHub Desktop.
Play a given audio file in Ruby
#!/usr/bin/env ruby
require 'rubygame'
include Rubygame
# Stuff that I had to do to get this running:
#
# brew install sdl sdl_mixer
# gem install rubygame rsdl
# Let's start by trying to play a random mp3 passed as an argument
mp3 = ARGV.pop
raise "No Mixer found! Make sure sdl_mixer is installed." unless defined? Sound
APP_ROOT = File.dirname File.expand_path( __FILE__ )
Sound.autoload_dirs << File.join( APP_ROOT, "sounds" )
# http://rubygame.org/wiki/NamedResources_tutorial#Autoloading_Resources
sound = Sound[mp3]
# sound = Sound.load mp3
sound.play :fade_in => 2, :stop_after => 5
while sound.playing?
sleep 1
end
# Kick Ass!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment