• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Executing files....mp3 style

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Author & Gold Digger
Posts: 7617
6
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the help, sorry about the nick name, I am now known as Michael O'Brien.
 
Ranch Hand
Posts: 233
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
reply
    Bookmark Topic Watch Topic
  • New Topic