Skip to content

Instantly share code, notes, and snippets.

@scottfrazer
Created February 22, 2011 18:10
Show Gist options
  • Save scottfrazer/839080 to your computer and use it in GitHub Desktop.
Save scottfrazer/839080 to your computer and use it in GitHub Desktop.
import java.util.Scanner;
import java.io.File;
import javax.swing.JOptionPane;
import javazoom.jl.player.Player;
import java.io.BufferedInputStream;
import java.io.FileInputStream;
public class mp3
{
public static void main(String[] args)
{
// User Interface
String bandString = JOptionPane.showInputDialog("Please enter a band you would like to listen to: ");
// Finding music by File name.
File musicdir = new File("C:\\java\\Music Test");
String[] files = musicdir.list();
if (files != null)
{
for (int i=0; i < files.length; i++)
{
if (files[i].contains(bandString))
{
try {
FileInputStream fis = new FileInputStream(files[i]);
BufferedInputStream bis = new BufferedInputStream(fis);
Player player = new Player(bis);
player.play();
} catch (Exception e) {
System.out.println(e);
}
break;
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment