User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Ruby section within the Web Development category of DaniWeb, a massive community of 332,772 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,876 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Ruby advertiser: SELL YOUR PRODUCT TODAY !
Mar 27th, 2006
Views: 3,564
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.
ruby Syntax
  1. # play a midi file or mod file using the SDL wrapper for Ruby
  2. # download RUDL from: http://sourceforge.net/projects/rudl/
  3. # file: rudl-0.8-for-ruby-1.8.2-setup-releasebuild.zip
  4. # includes the needed SDL .dll files
  5. # run install-on-windows.rb and follow instructions
  6. # tested with Ruby182 and Windows XP vegaseat 17mar2006 (yeah Irish!)
  7.  
  8. require "RUDL"
  9. # this gets rid of the namespace
  10. include RUDL
  11.  
  12. # pick a midi file you have in the workfolder
  13. # or add the full path to the filename
  14. filename = "TeaFor2.mid"
  15. music = Music.new(filename)
  16. music.play
  17.  
  18. # needed to play music to the end
  19. gets
Post Comment

Only community members can submit or comment on code snippets. You must register or log in to contribute.

DaniWeb Marketplace (Sponsored Links)
All times are GMT -4. The time now is 9:23 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC