aspose file tools*
The moose likes Beginning Java and the fly likes Executing files....mp3 style Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Executing files....mp3 style" Watch "Executing files....mp3 style" New topic
Author

Executing files....mp3 style

obrienmp
Greenhorn

Joined: Feb 15, 2002
Posts: 1
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

Joined: Aug 26, 2001
Posts: 7610
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 ]

SCJP 5, SCJD, SCBCD, SCWCD, SCDJWS, IBM XML
[Blog] [Blogroll] [My Reviews] My Linked In
Michael O'Brien
Greenhorn

Joined: Feb 15, 2002
Posts: 2
Thanks for the help, sorry about the nick name, I am now known as Michael O'Brien.
Arun Boraiah
Ranch Hand

Joined: Nov 28, 2001
Posts: 233
hi
Try this.
public class Excute {
public static void main(String args[])throws Exception{
Runtime run =Runtime.getRuntime();
run.exec("notepad");
}


}
-arun


Sharing is learning
Michael O'Brien
Greenhorn

Joined: Feb 15, 2002
Posts: 2
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Executing files....mp3 style
 
Similar Threads
why that happen
Tokenize numbers only, skip words
Datatype casting. Split Strings to double 2D array. (loss of precision)
search files in directory for string and return count
Tokens into array, datatype??