Question: GUI music player Step 1: At this level use a combination of a text (Terminal) interface and a GUI interface. For some of the following
GUI music player
Step 1: At this level use a combination of a text (Terminal) interface and a GUI interface. For some of the following you will be able to re-use your code from PS 3.4: Music player with menu.
The program must read in (from a file) at least 4 albums with up to 15 tracks for each album as well as the file location of each track.
Your application must:
-
Display the albums in the Terminal window including album information such as title and artist and allow the user to select an album, at which point you should display the tracks;
-
The user should be able to select an album and your player should start playing the albums tracks. At this point the user should be able to use buttons on a graphical panel and/or key presses to play, stop or skip tracks (i.e skip to the next track on the album). All other user interaction as in 1 above - could be text based. You must use an audio API for this component;
-
Whichever track is playing you should display 'The track you selected' then the track name from the Album: then the album name then is now playing. This could be in the Terminal window or on the GUI screen.
Using ruby
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
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
