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

Artist

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'

TOP_COLOR = Gosu::Color.new(0xFF1EB1FA)
BOTTOM_COLOR = Gosu::Color.new(0xFF1D4DB5)

module ZOrder
BACKGROUND, PLAYER, UI = *0..2
end

module Genre
POP, CLASSIC, JAZZ, ROCK = *1..4
end

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

class ArtWork
   attr_accessor :bmp

   def initialize (file)
       @bmp = Gosu::Image.new(file)
   end
end

# 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
   end

# 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
end

# 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
end


# 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)
end


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

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

# Draw a coloured background using TOP_COLOR and BOTTOM_COLOR

   def draw_background

   end

# Not used? Everything depends on mouse actions.

   def update
   end

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

   def draw
       # Complete the missing code
       draw_background
   end

    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?
   end
   end

end

# Show is a method that loops through update and draw

MusicPlayerMain.new.show 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:

https://twitter.com/emezac/status/1121872367716900864?s=20

Check this out:

Hope this helps :smile:
Also, for further details you can find the ruby music player video on my channel