Hallo, ich hab mir so ein Player gebaut der MP3- Dateien abspielt, jetzt hab ich aber das Problem das ich immer nur eine Datei einlesen kann und keine Idee habe wie ich es umsetze das man mehrere Dateien einlesen kann und diese dann je nach Wunsch abspielen kann.
Wäre ganz nett wenn mir jemand nen kleinen Denkanschub oder nen Hinweis geben könnte wie man sowas umsetzen kann.
Das hier ist der Teil wo man die Datei auswählt:
[highlight=Java]
if(aktion.equals("Durchsuchen")){
JFileChooser chooser = new JFileChooser();
chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
int option = chooser.showOpenDialog(ProjektNeu.this);
if(option == JFileChooser.APPROVE_OPTION){
statusbar.setText("Sie spielen: "+chooser.getSelectedFile().getName() +" ab");
File pfad = chooser.getSelectedFile();
if(pfad.isFile()){
try{
RandomAccessFile ranFile = new RandomAccessFile(pfad,"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");
return;
}
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.getAbsolutePath();
try{
p = new AdvancedPlayer(new FileInputStream(dateipfad));
}
catch(Exception e){
}
}
else{
statusbar.setText("Sie haben abgebrochen");
}
}
[/highlight]
Wäre ganz nett wenn mir jemand nen kleinen Denkanschub oder nen Hinweis geben könnte wie man sowas umsetzen kann.
Das hier ist der Teil wo man die Datei auswählt:
[highlight=Java]
if(aktion.equals("Durchsuchen")){
JFileChooser chooser = new JFileChooser();
chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
int option = chooser.showOpenDialog(ProjektNeu.this);
if(option == JFileChooser.APPROVE_OPTION){
statusbar.setText("Sie spielen: "+chooser.getSelectedFile().getName() +" ab");
File pfad = chooser.getSelectedFile();
if(pfad.isFile()){
try{
RandomAccessFile ranFile = new RandomAccessFile(pfad,"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");
return;
}
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.getAbsolutePath();
try{
p = new AdvancedPlayer(new FileInputStream(dateipfad));
}
catch(Exception e){
}
}
else{
statusbar.setText("Sie haben abgebrochen");
}
}
[/highlight]