This site requires JavaScript, please enable it in your browser!
Greenfoot back
Gazzzah
Gazzzah wrote ...

2012/7/22

Using 'lists'

Gazzzah Gazzzah

2012/7/22

#
I'm planning to make an app that amongst other things, plays music in a shuffled order. It needs to be pretty adaptable to adding new songs (it would be awesome if the app could get the files from an external folder) and sorting them into new playlists but ultimately my concern is getting them to be played in a random order. I imagine I could create a 'list' of the songs and have it sort into a random order. Thing is I'm not very familiar with using lists. So to someone more experienced, does what i plan to do sound feasible? Can you recommend a better way? Do you have any idea how i can use this function to achieve this purpose? Thanks.
darkmist255 darkmist255

2012/7/22

#
Here's your class information for Lists What you're trying to do should be perfectly feasible, although it won't work on the Greenfoot gallery (You'll have to download it/run it locally so that it has permission to read your files). If you work at it one part at a time you'll learn a lot and shouldn't run into too many roadblocks.
Gazzzah Gazzzah

2012/7/22

#
Ok thanks! I don't plan on publishing it but rather as a utility for personal use, so that's all good. Thank you.
Gazzzah Gazzzah

2012/7/22

#
Is there a way I can sequentially return all the file names in the sounds folder or a different folder (preferably the latter) for so they can be added to a class that is listed?
darkmist255 darkmist255

2012/7/22

#
I was actually looking into that as well. I'll tell you if I end up finding something, but I'm sure there is a way. If you can get that to work that's probably the best plan of action. I wouldn't think that it would be restricted to the sounds folder, since you would be using external libraries anyway.
danpost danpost

2012/7/22

#
Create a File object using the directory path/name and use the 'list()' method to return an array of String representing the files (and sub-folders, or anything else that may be within that directory). Check out the documentation on the File class.
darkmist255 darkmist255

2012/7/22

#
listFiles() might perform a tiny bit better and might help you filter out what you don't want. Also, thanks danpost, didn't know that File had a method like that.
danpost danpost

2012/7/22

#
Well, I took some time looking through the APIs, and came up empty. That is, until I remembered an in-house project I had done for someone that required some directory searching; so, I located the project and reviewed the source. I almost gave up on that idea when I saw the JFileChooser, FileNameExtensionFilter, and JFrame import statements (nothing refering directly to Files themselves), but decided to look deeper in the code. I found a reference to the File class within the code and reviewed the imports, again. Then, I saw it: import java.io.*;. That had to be it! I went back to the APIs to review (and acquired the shortcut) before posting.
You need to login to post a reply.