Directions

advertisement
Lab - Music Player
For this lab, we are going to create a music playlist from the files in a folder, creates a custom
playlist, and then play the songs on the playlist.
STEP 0: Run the program and see what it does (put your headphone on first!)
STEP 1: Take a look at the existing code
I have given you some starter code. You do not need to modify these methods or even call
them. I did all that work for you. But here’s a little synopsis of what they do:



loadSongs reads all the .wav files in the songDirectory and puts the files names of
the songs into the ArrayList<String> called songs. Currently the method actually only
reads .wav files that end in “-clip” because I wanted to make it faster for testing--you
could change the line of code that checks this if you wanted play the entire song.
playSong takes a path to a .wav file and plays it. If there is a song already playing, the
method first stops the previous song before playing the new one.
the main already contains all the program logic needed. You may alter this code if you
want, but you will not need to in order to make the program function.
STEP 2: Write the listSongs method
This method should print all the tracks in the songs arraylist with track numbers in the front.
Make sure that track numbers begin with 1, not 0.
STEP 3: Write the shuffle method
This method should shuffle all the songs in the song list by choosing a random index and
moving that song to the end of the list. You should do this a number of times (7? 10? the size of
the list? This is your choice) to ensure that the list properly shuffles.
STEP 4: Write the customizePlaylist method.
This method should allow the user to reorder, remove, or shuffle songs. You should display the
current track list (by calling the listSongs method). Then you should give the user options to
customize their list until they are ready to play the playlist. If the user chooses to shuffle their
playlist, you should call the shuffle method that you wrote in step 3. Once this method ends,
the songs will begin to play automatically.
Output should look something like this:
----jGRASP exec: java -ea MusicPlayer
==============LOADING SONGS================
DIRECTORY songs/
Loading Billionaire-clip.wav
Loading Bust a Move-clip.wav
Loading Defying Gravity-clip.wav
Loading Imagine-clip.wav
Loading Just The Way You Are-clip.wav
===========================================
---------------CUSTOMIZE PLAYLIST--------------TRACK LIST:
1. Billionaire-clip.wav
2. Bust a Move-clip.wav
3. Defying Gravity-clip.wav
4. Imagine-clip.wav
5. Just The Way You Are-clip.wav
CUSTOMIZATION OPTIONS:
1. Reorder
2. Remove a song
3. Shuffle
4. Play playlist
What would you like to do? > 1
Which track would you like to move? 5
New track number for My Life Would Suck Without You-clip.wav? 3
TRACK LIST:
1. Billionaire-clip.wav
2. Bust a Move-clip.wav
3. Just The Way You Are-clip.wav
4. Defying Gravity-clip.wav
5. Imagine-clip.wav
CUSTOMIZATION OPTIONS:
1. Reorder
2. Remove a song
3. Shuffle
4. Play playlist
What would you like to do? > 2
Which track would you like to remove? 4
TRACK LIST:
1. Billionaire-clip.wav
2. Bust a Move-clip.wav
3. Just The Way You Are-clip.wav
4. Imagine-clip.wav
CUSTOMIZATION OPTIONS:
1. Reorder
2. Remove a song
3. Shuffle
4. Play playlist
What would you like to do? > 4
---------------MUSIC STARTED--------------Currently playing... songs/Billionaire-clip.wav
Press enter to hear the next song.
Currently playing... songs/Bust a Move-clip.wav
Press enter to hear the next song.
Currently playing... songs/Just the Way You Are-clip.wav
Press enter to hear the next song.
Currently playing... songs/Imagine-clip.wav
Press enter to hear the next song.
--------------END OF PLAYLIST-----------------jGRASP: process ended by user.
Download