GUI music player in ruby

So I am trying to write a GUI Music Player program using Ruby. The program must read in (from a file) at least four albums and up to 15 tracks for each album.

The information read from the file should include:

Number of Albums

Album title


Artwork file name (place your artwork in an /images folder under the main folder where you run the program)

The number of tracks

The title of each track

The file location of each track

User interaction must be entirely through a GUI. GUI interface should show all the albums using either a text description, artwork or both. Users should be able to click on any Album information (i.e the artwork) and the tracks will be listed. The user should then be able to click on a track to play that track. The currently playing track must be indicated somehow (e.g the track could be highlighted or display a simple text message ‘Now playing …’). If the user clicks on another track (for the current album or another album) then any currently playing track should be stopped and the most recently selected track start playing. The Gosu audio API for this component.

I was able to get a hold of the following skeleton code to get me started. However, since I am not very experienced with GUI programming, I was hoping someone would be kind enough to provide me a few pointers on changes I could make to the code below to get me started on GUI programming.

require 'rubygems'
require 'gosu'


module ZOrder

module Genre

GENRE_NAMES = ['Null', 'Pop', 'Classic', 'Jazz', 'Rock']

class ArtWork
   attr_accessor :bmp

   def initialize (file)
       @bmp =

# Put your record definitions here

class MusicPlayerMain < Gosu::Window

   def initialize
   super 600, 800
   self.caption = "Music Player"

       # Reads in an array of albums from a file and then prints all the albums in the
       # array to the terminal

# Put in your code here to load albums and tracks

# Draws the artwork on the screen for all the albums

def draw_albums albums
# complete this code

# Detects if a 'mouse sensitive' area has been clicked on
# i.e either an album or a track. returns true or false

def area_clicked(leftX, topY, rightX, bottomY)
# complete this code

# Takes a String title and an Integer ypos
# You may want to use the following:
def display_track(title, ypos)
   @track_font.draw(title, TrackLeftX, ypos, ZOrder::PLAYER, 1.0, 1.0, Gosu::Color::BLACK)

# Takes a track index and an Album and plays the Track from the Album

def playTrack(track, album)
   # complete the missing code
           @song =[track].location)
# Uncomment the following and indent correctly:
   #   end
   # end

# Draw a coloured background using TOP_COLOR and BOTTOM_COLOR

   def draw_background


# Not used? Everything depends on mouse actions.

   def update

# Draws the album images and the track list for the selected album

   def draw
       # Complete the missing code

    def needs_cursor?; true; end

   # If the button area (rectangle) has been clicked on change the background color
   # also store the mouse_x and mouse_y attributes that we 'inherit' from Gosu
   # you will learn about inheritance in the OOP unit - for now just accept that
   # these are available and filled with the latest x and y locations of the mouse click.

   def button_down(id)
       case id
   when Gosu::MsLeft
       # What should happen here?


# Show is a method that loops through update and draw if __FILE__ == $0

I do not understand you chose Gosu as a Front-end, it is more appropriate for Game Development. I use to use Gnome-Gtk with Ruby in this way:

This repo is a minimalist example using Observer pattern as an engine for my MVC approach:

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs