• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Executing files....mp3 style

 
obrienmp
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello everyone.
I am new to this, so take it easy on me
I was trying to learn how to mess with files, and I decided to write a program that will search a specified directory for a specified file extension. so if i wanted to search C:\!files\ for .mp3 files, it returns a printed list of the files with that extension. well, now that i can do that, what do i do with the files? i have winamp on my computer, and i would like to play these mp3 files like a playlist, but have no way to go about executing an mp3 file, or even opening winamp with java. anyone have any ideas? what classes/methods/etc i should use?
CODE:
import java.io.*;
public class Search {
public static void main(String args[]) throws java.io.IOException {

// create a buffered reader "in" to store a string that you input
// from the keyboard.
BufferedReader in =
new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter the directory for search...");

// reading in the string typed from the keyboard, and stored as String sBlah
String sBlah = in.readLine();

System.out.println("String in = " + sBlah);
File dir = new File(sBlah);
System.out.println("dir.isDirectory()=" + dir.isDirectory());
if(dir.isDirectory() == true) {
System.out.println("Enter the file extension you would like to search for.");
System.out.println("Avoid * and quotations.");
final String sExtension = in.readLine();
in.close();
String[] sPlayList = dir.list(new FilenameFilter() {
public boolean accept(File f, String s)
{
return(s.endsWith(sExtension));
} // end accept
});

System.out.println("Listing files....");
for (int i = 0; i < sPlayList.length; i++)
{
System.out.println(sPlayList[i]);
} // end for
if(sPlayList.length == 0) {
System.out.println("There aren't any Mp3's in this directory dummy!");
} // end if
} // end if
else
{
System.out.println("The directory that you entered does not exist...Typical..");
} // end else

} // end main
} // end class Search

Mike O'Brien
 
Valentin Crettaz
Gold Digger
Sheriff
Posts: 7610
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, have a look at the methods exec() in class java.lang.Runtime which allow you to start a new process from a Java application. You can build a command line with "winamp" in it and some MP3 files as arguments and then feed it as arguments to exec()... Might be worth trying...
Moreover, we'd like you to read the Javaranch Naming Policy and modify your "Publicly Displayed Name". Thank you for your collaboration.
[ February 15, 2002: Message edited by: Valentin Crettaz ]
 
Michael O'Brien
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the help, sorry about the nick name, I am now known as Michael O'Brien.
 
Arun Boraiah
Ranch Hand
Posts: 233
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi
Try this.
public class Excute {
public static void main(String args[])throws Exception{
Runtime run =Runtime.getRuntime();
run.exec("notepad");
}


}
-arun
 
Michael O'Brien
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I ended up doing something like this....
for (int i = 0; i < sPlayList.length; i++)
{
System.out.println(sPlayList[i]);
String sTrack = (sBlah + sPlayList[i]);
String sWinPlay = "C:\\Program Files\\Winamp\\winamp.exe " + sTrack;
try
{
Process proc = Runtime.getRuntime().exec(sWinPlay);
proc.waitFor();
int rc = proc.exitValue();
System.out.println("rc=" + rc);
} // end try
catch(InterruptedException e)
{
System.out.println("InterruptedException caught for Windows Media Player: " +
e.getMessage());
} // end catch
catch(IOException e)
{ {
System.out.println("IOException caught for Windows Media Player: " +
e.getMessage());
} // end catch
} // end for
but now, it will loop through, and it will call each song from the PlayList[] array, and pass the song name into the string winplay as a parameter, and everything works fine, except it waits for the entire media player .exe to close before it calls the next one. what can i do to get windows media player to exit/terminate/close/etc?
Mike
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic