import java.io.*;
import javax.swing.*;
import javax.swing.JFileChooser;
import javax.swing.event.*;
import java.awt.*;
import java.util.ArrayList;
import java.awt.event.*;
import javazoom.jl.player.*;
import javazoom.jl.player.advanced.*;
import javazoom.jl.decoder.*;
public class Projekt1 extends JFrame{
JButton dir = new JButton("Durchsuchen");
JButton play = new JButton("Play");
JButton stop = new JButton("Stop");
JTextArea statusbar = new JTextArea("Folgende Lieder sind ausgewählt:");
String dateipfad;
startThread demoThread;
boolean running = true;
AdvancedPlayer p;
int i = 0;
Projekt1(){
super("Projekt");
setSize(350,200);
setDefaultCloseOperation(EXIT_ON_CLOSE);
Lauscher l = new Lauscher();
Container c = getContentPane();
c.setLayout(new FlowLayout());
dir.addActionListener(l);
play.addActionListener(l);
stop.addActionListener(l);
c.add(dir);
c.add(play);
c.add(stop);
c.add(statusbar);
}
class Lauscher implements ActionListener{
public void actionPerformed(ActionEvent ae){
String aktion = ae.getActionCommand();
if(aktion.equals("Durchsuchen")){
JFileChooser chooser = new JFileChooser();
chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
chooser.setMultiSelectionEnabled(true);
int option = chooser.showOpenDialog(Projekt1.this);
if(option == JFileChooser.APPROVE_OPTION){
statusbar.setText(statusbar.getText()+"\n"+""+chooser.getSelectedFile().getName() +"");
statusbar.setEditable(false);
File[] pfad = chooser.getSelectedFiles();
for(int i=0; i<pfad.length; i++){
if(pfad[i].isFile()){
try{
RandomAccessFile ranFile = new RandomAccessFile(pfad[i],"r");
byte[] bytearr = new byte[128];
ranFile.seek(ranFile.length()-128);
ranFile.read(bytearr,0,128);
String a = new String (bytearr,"US-ASCII");
if(!a.substring(0,3).equals("TAG")){
System.out.println("Keine Informationen vorhanden");
continue;
}
String title,artist,album,year,comment;
System.out.println("TITEL: "+a.substring(3,33).trim());
System.out.println("ARTIST: "+a.substring(33,63).trim());
System.out.println("ALBUM: "+a.substring(63,93).trim());
System.out.println("YEAR: "+a.substring(93,97).trim());
System.out.println("COMMENT: "+a.substring(97,126).trim());
System.out.println("GENRE: "+bytearr[127]);
}
catch(IOException e){
System.out.println(e);
}
}
dateipfad = pfad[i].getAbsolutePath();
}
try{
p = new AdvancedPlayer(new FileInputStream(dateipfad));
}
catch(Exception e){
}
}
else{
statusbar.setText("Sie haben abgebrochen");
}
}
if(aktion.equals("Play")){
try{
p.close();
demoThread = new startThread();
running = true;
demoThread.start();
try{
p = new AdvancedPlayer(new FileInputStream(dateipfad));
}
catch(Exception e){
}
}
catch(Exception e){
}
}
if(aktion.equals("Stop")){
if(running){
demoThread = null;
}
running = false;
p.close();
try{
p = new AdvancedPlayer(new FileInputStream(dateipfad));
}
catch(Exception e){
}
}
}
}
class startThread extends Thread{
public void run(){
try{
p.play();
}
catch(Exception e){
}
}
}
public static void main(String[] args) throws FileNotFoundException, JavaLayerException{
Projekt1 pn = new Projekt1();
pn.setVisible(true);
pn.setLocation(300,300);
}
}