-
-
Save abeeku/972406 to your computer and use it in GitHub Desktop.
Play a given audio file in Ruby
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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