Play Sound and Music the SDL Way (Ruby)

vegaseat 0 Tallied Votes 275 Views Share

Using an SDL (Simple DirectMedia Layer) wrapper is one way to play sound and music with Ruby. I have tested this snippet with .MID .MOD and .WAV files and it performs well. There are several SDL wrappers for Ruby available, I picked RUDL because of its simplicity. RUDL is great for writing games.

# play a midi file or mod file using the SDL wrapper for Ruby
# download RUDL from:
# file:
# includes the needed SDL .dll files
# run install-on-windows.rb and follow instructions
# tested with Ruby182 and Windows XP    vegaseat     17mar2006  (yeah Irish!)

require "RUDL"
# this gets rid of the namespace
include RUDL

# pick a midi file you have in the workfolder
# or add the full path to the filename
filename = "TeaFor2.mid"
music =

# needed to play music to the end
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.